Views
No views yet

Cyfieithwch y testun Saesneg canlynol i'r Gymraeg.
### Saesneg:
{prompt}
### Cymraeg:
Translate the following Welsh text to English.
### Welsh:
{prompt}
### English:
import transformers
device="cuda"
model_name = 'BangorAI/cyfieithydd-7b-fersiwn-3'
model = transformers.AutoModelForCausalLM.from_pretrained(model_name, load_in_8bit=True)
tokenizer = transformers.AutoTokenizer.from_pretrained(model_name)
def generate_response(text):
# Format the input using the provided template
prompt = f"Cyfieithwch y testun Saesneg canlynol i'r Gymraeg.\n\n### Saesneg:\n{text}\n\n### Cymraeg:\n"
# Tokenize and encode the prompt
inputs = tokenizer.encode(prompt, return_tensors="pt", add_special_tokens=False).to(device)
# Generate a response
outputs = model.generate(inputs, max_length=1000, num_return_sequences=1, do_sample=True, temperature=0.01)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response
text="""The extension of the Flying Start programme is part of a phased expansion of early years provision to all two-year-olds in Wales, with a particular emphasis on strengthening Welsh-medium provision. This is a commitment in the Co-operation Agreement between the Welsh Government and Plaid Cymru."""
response = generate_response(text)
print(response)