File size: 3,034 Bytes
883146d
 
1c7bb4c
 
 
 
 
883146d
8664bd6
 
 
 
1c7bb4c
 
 
 
cdf50ad
 
1c7bb4c
 
 
8664bd6
 
1c7bb4c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
---
license: apache-2.0
datasets:
- techiaith/cofnodycynulliad_en-cy
- BangorAI/hysbysiadau-llyw-cymru-1
language:
- cy
---
![cyfieithydd-7b-fersiwn-3](https://huggingface.co/BangorAI/cyfieithydd-7b-fersiwn-3/resolve/main/cyfieithydd.jpg)   
# Cyfieithydd 7b Fersiwn 3  #

Model cyfieithu arbrofol sy'n defnyddio LLM Trawsnewidiol.

Mae'r model LLM yn seiliedig ar [BangorAI/mistral-7b-cy-epoch-2](https://huggingface.co/BangorAI/mistral-7b-cy-epoch-2), sef y model Mistral-7B wedi hyfforddiant parhaus ar gyfer y Gymraeg.

Cafodd y model hyfforddiant cywrain pellach ar y cyfeithiadau canlynol:
* data [Cofnod y Cynulliad](https://huggingface.co/datasets/techiaith/cofnodycynulliad_en-cy) wedi’u paratoi gan [TechIaith](https://huggingface.co/techiaith)
* data [Hysbysiadau Llywodraeth Cymru](https://www.llyw.cymru/hysbysiadau) yn archif [BangorAI/hysbysiadau-llyw-cymru-1](https://huggingface.co/datasets/BangorAI/hysbysiadau-llyw-cymru-1) 

## Demo

Gallwch roi gynnig ar esiampl o'r model yma: [https://demo.bangor.ai/](https://demo.bangor.ai/)   
(cofiwch ddewis yr opsiwn "Trosi En -> Cy")

### Fformat Sgwrs

Mae'r hyfforddiant cywrain wedi defnyddio'r fformat canlynol ar gyfer trosi o'r Saesneg i'r Gymraeg:
```
Cyfieithwch y testun Saesneg canlynol i'r Gymraeg.
### Saesneg:
{prompt}

### Cymraeg:

```

a'r naill ffordd i'r llall:
```
Translate the following Welsh text to English.
### Welsh:
{prompt}

### English:

```

## Sut i'w ddefnyddio

Mae'r model Mistral-7B-v-0.1 sy'n tanseilio'r model yma yn defnyddio ffenestr cyd-destun maint 4k, felly mae'n ofyniad i becynnu'r testyn fesul paragraff a'u bwydo i mewn i'r LLM yn eu tro.

Dyma enghraifft mewn Python:

```
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)

```

## Hawlfraint
Mae'r data Cofnod y Cynulliad ac Hysbysiadau Llywodreath Cymru dan [Drwydded Llywodraeth Agored](https://www.nationalarchives.gov.uk/doc/open-government-licence-cymraeg/version/3/).