Views
No views yet
1>>> from transformers import AutoModel, AutoTokenizer
2>>>
3>>> model_id = "rmihaylov/gpt2-small-bg"
4>>> tokenizer = AutoTokenizer.from_pretrained(model_id)
5>>> model = AutoModel.from_pretrained(model_id, trust_remote_code=True)
6>>>
7>>> input_ids = tokenizer.encode(
8>>> "Здравей,",
9>>> add_special_tokens=False,
10>>> return_tensors='pt')
11>>>
12>>> output_ids = model.generate(
13>>> input_ids,
14>>> do_sample=True,
15>>> max_length=50,
16>>> top_p=0.92,
17>>> pad_token_id=2,
18>>> top_k=0)
19>>>
20>>> output = tokenizer.decode(output_ids[0])
21>>>
22>>> output = output.replace('<|endoftext|>', '\n\n\n')
23>>> output = output.replace('<|unknown|>', '')
24>>> output = output.replace('▁', ' ')
25>>> output = output.replace('<|n|>', '\n')
26>>>
27>>> print(output)
28
29Здравей, Ани! Не е ли прекрасно?
30 Нещото се засмя. Зъбите му блеснаха.
31 — Ще те разведа насам-натам!
32 Ани се замисли, когато той си тръгна. Може би не искаше да го еBecause large-scale language models like GPT-2 do not distinguish fact from fiction, we don’t support use-cases that require the generated text to be true.Additionally, language models like GPT-2 reflect the biases inherent to the systems they were trained on, so we do not recommend that they be deployed into systems that interact with humans > unless the deployers first carry out a study of biases relevant to the intended use-case. We found no statistically significant difference in gender, race, and religious bias probes between 774M and 1.5B, implying all versions of GPT-2 should be approached with similar levels of caution around use cases that are sensitive to biases around human attributes.