Question Answering
Transformers
Safetensors
Arabic
Inference Endpoints
MohammedNasser commited on
Commit
2ada3ee
1 Parent(s): 7b4a41f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +16 -19
README.md CHANGED
@@ -86,34 +86,31 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
86
  import torch
87
 
88
  model_name = "MohammedNasser/silma_9b_instruct_ft"
 
89
 
90
  # Load model and tokenizer
91
- tokenizer = AutoTokenizer.from_pretrained(model_name)
92
- model = AutoModelForCausalLM.from_pretrained(
93
- model_name,
94
- torch_dtype=torch.float16,
95
- device_map="auto",
96
- )
97
 
98
  # Create pipeline
99
- qa_pipeline = pipeline(
100
  "text-generation",
101
- model=model,
102
- tokenizer=tokenizer,
103
- max_new_tokens=50,
104
- do_sample=True,
105
- temperature=0.7,
106
- top_p=0.95,
107
- return_full_text=False
108
  )
109
 
 
 
 
 
110
  # Example usage
111
- question = "إذا كان لديك ثلاث سيارات، وبعت واحدة منها، كم سيارة ستبقى لديك؟"
112
- prompt = f"Question: {question}\nAnswer:"
113
- response = qa_pipeline(prompt)[0]['generated_text']
114
 
115
- print(f"Question: {question}")
116
- print(f"Answer: {response}")
117
  ```
118
 
119
  ## Performance
 
86
  import torch
87
 
88
  model_name = "MohammedNasser/silma_9b_instruct_ft"
89
+ user_question = "إذا كان لديك ثلاث سيارات، وبعت واحدة منها، كم سيارة ستبقى لديك؟"
90
 
91
  # Load model and tokenizer
92
+ import torch
93
+ from transformers import pipeline
 
 
 
 
94
 
95
  # Create pipeline
96
+ pipe = pipeline(
97
  "text-generation",
98
+ model=model_name,
99
+ torch_dtype= torch.bfloat16,
100
+ device="cuda",
101
+ return_full_text=False,
 
 
 
102
  )
103
 
104
+ messages = [
105
+ {"role": "user", "content": user_question },
106
+ ]
107
+
108
  # Example usage
109
+ response = pipe(messages, max_new_tokens=128)
110
+ assistant_response = outputs[0]["generated_text"]
 
111
 
112
+ print(f"Question: {user_question}")
113
+ print(f"Answer: {assistant_response}")
114
  ```
115
 
116
  ## Performance