Downloads · 30 days
11
4% of all-time downloads
tykea/mBart-large-50-KQA
mBart-large-50-KQA is a machine learning model from tykea. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers. The card lists the license as mit.
Import model and tokenizer from transformer libray
Downloads · 30 days
11
4% of all-time downloads
All-time downloads
283
Public
Parameters
611M
2.4 GB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors2.4 GB · 100%
From the Hugging Face model README
Import model and tokenizer from transformer libray
# Load model directly
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("tykea/mBart-large-50-KQA")
model = AutoModelForSeq2SeqLM.from_pretrained("tykea/mBart-large-50-KQA")
Define function to take question and pass to the model
import torch
#ask function for easier asking
def ask(custom_question):
# Tokenize the input
inputs = tokenizer(
f"qestion: {custom_question}",
return_tensors="pt",
truncation=True,
max_length=512,
padding="max_length"
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
inputs = {key: value.to(device) for key, value in inputs.items()}
model.eval()
with torch.no_grad():
outputs = model.generate(
input_ids=inputs["input_ids"],
max_length=50,
num_beams=4,
repetition_penalty=2.0,
early_stopping=True,
do_sample=True,
top_k=50,
top_p=0.95,
temperature=0.7,
)
answer = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(f"Question: {custom_question}")
print(f"Answer: {answer}")
Then call the function #ask function
question = "តើប្អូនកើតនៅប្រទេសណា?"
ask(question)
#output
Question: តើប្អូនកើតនៅប្រទេសណា?
Answer: ប្អូនកើតនៅប្រទេសចិន