Views
No views yet
| 입력 문장 | 방언: 게난 저 어머니 더 나이 먹어가기 전에 여기 와야 될 건디 | 표준어: 그러니깐 저 어머니 더 나이 먹어가기 전에 여기 와야 될 건데 |
|---|---|---|
| 방언 통역기 출력 | 표준어: 그러니까 저 어머니 더 나이 먹어가기 전에 여기 와야 될 건데 | 방언: 게난 저 어멍 더 나이 먹어가기 전에 여기 와야 될 건디 |
| 입력 문장 | 방언: 자이 폴에 독솔 막 난 거 보난 언 생이우다 | 표준어: 재 팔에 닭살이 막 난 거 보니, 추운 모양이다 |
|---|---|---|
| 방언 통역기 출력 | 표준어: 쟤 팔에 닭살이 많이 난 거 보니까 추운 모양입니다 | 방언: 재 폴에 독솔 막 난 거 보난 언 생이우다 |
1import transformers
2import torch
3
4model_id = "sjbaek/gemma2-2b-it-korean-dialect"
5tokenizer = transformers.AutoTokenizer.from_pretrained(model_id, add_eos_token=True)
6
7pipeline = transformers.pipeline(
8 "text-generation",
9 model=model_id,
10 tokenizer=tokenizer,
11 torch_dtype=torch.float16,
12 device_map="auto",
13 max_new_tokens = 512,
14)
15
16
17def dialect_to_standard(text, dialect_type):
18 return [
19 {
20 "role":"user",
21 "content": "Convert the following sentence or word which is {}'s dialect to standard Korean:\n\n{}".format(dialect_type, text)
22 }
23 ]
24
25
26def standard_to_dialect(text, dialect_type):
27 return [
28 {
29 "role":"user",
30 "content": "Convert the following sentence or word which is standard Korean to {}'s dialect :\n\n{}".format(dialect_type, text)
31 }
32 ]
33
34outputs = pipeline(
35 dialect_to_standard("우리 동생도 요번에 월요일날 미깡 타카부댄 내려왔당 못 타난", "제주도"),
36 do_sample=True,
37 temperature=0.1,
38 top_p=0.90,
39 add_special_tokens=True
40)
41
42print(outputs[0]["generated_text"][-1])
43# {'role': 'assistant', 'content': '우리 동생도 요번에 월요일날 귤 타고 왔다가 못 타니까'}
44
45outputs = pipeline(
46 standard_to_dialect("그러니깐 저 어머니 더 나이 먹어가기 전에 여기 와야 될 건데", "제주도"),
47 do_sample=True,
48 temperature=0.1,
49 top_p=0.90,
50 add_special_tokens=True
51)
52
53print(outputs[0]["generated_text"][-1])
54# {'role': 'assistant', 'content': '게난 저 어멍 더 나이 먹어가기 전에 여기 와야 될 건디'}