Downloads · 30 days
5
26% of all-time downloads
adi2606/MenstrualQA
MenstrualQA is a machine learning model from adi2606. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as mit.
IMPORTANT: This model is sensitive to the chat template used. Ensure you use the correct template:
Downloads · 30 days
5
26% of all-time downloads
All-time downloads
19
Public
Parameters
155M
622 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors621 MB · 100%
From the Hugging Face model README
IMPORTANT: This model is sensitive to the chat template used. Ensure you use the correct template:
<s>system
[System message]</s>
<s>user
[Your question or message]</s>
<s>assistant
[The model's response]</s>
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
# Determine the device to use (GPU if available, otherwise CPU)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load the model and tokenizer, then move the model to the appropriate device
model = AutoModelForCausalLM.from_pretrained("adi2606/MenstrualQA").to(device)
tokenizer = AutoTokenizer.from_pretrained("adi2606/MenstrualQA")
# Function to generate a response from the chatbot
def generate_response(message: str, temperature: float = 0.4, repetition_penalty: float = 1.1) -> str:
# Apply the chat template and convert to PyTorch tensors
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": message}
]
input_ids = tokenizer.apply_chat_template(
messages, add_generation_prompt=True, return_tensors="pt"
).to(device)
# Generate the response
output = model.generate(
input_ids,
max_length=512,
temperature=temperature,
repetition_penalty=repetition_penalty,
do_sample=True
)
# Decode the generated output
generated_text = tokenizer.decode(output[0], skip_special_tokens=True)
return generated_text
# Example usage
message = "how to stop pain during menstruation?"
response = generate_response(message)
print(response)