File size: 3,060 Bytes
82d4116
5517ece
 
b2abd4e
5517ece
82d4116
 
 
 
0e036a2
 
99f8038
82d4116
854b82e
82d4116
 
5517ece
82d4116
5517ece
82d4116
0e036a2
51c4833
82d4116
ee12fbf
 
 
 
 
 
5517ece
82d4116
5517ece
82d4116
5517ece
82d4116
 
5517ece
 
82d4116
5517ece
 
 
 
82d4116
0e036a2
82d4116
 
5517ece
82d4116
5517ece
82d4116
5517ece
 
 
82d4116
5517ece
 
 
 
82d4116
5517ece
82d4116
 
1e9b42a
82d4116
3b94df9
82d4116
4a7e4c6
 
 
 
3191016
4a7e4c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1e9b42a
0e036a2
 
 
4a7e4c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
---
language:
- ja
library_name: transformers
pipeline_tag: text-generation
---

# Model Card for Model ID

This model can be used to convert Japanese IPA back to normal text. 

**Upgraded to a more powerful model (3B), with a larger dataset and trained for more steps.**

This model should only be used for the specific IPA conversion that's generated by [Hibiki ASR](https://huggingface.co./Respair/Hibiki_ASR_Phonemizer_v0.2). so this may not have the optimal result on any IPA text.


## Model 

### Usage




in the terminal:
```bash
python -m vllm.entrypoints.openai.api_server --model Respair/Japanese_Phoneme_to_Grapheme_LLM--port 8000
```

now you can simply use it:
```python

# pip install vllm

from openai import OpenAI


openai_api_key = "EMPTY"
openai_api_base = "http://localhost:8000/v1"

client = OpenAI(
    api_key=openai_api_key,
    base_url=openai_api_base,
)

model_name = "Respair/Japanese_Phoneme_to_Grapheme_LLM"


def p2g(param):

    chat_response = client.chat.completions.create(

        model=model_name,
        max_tokens=512,
        temperature=0.01,

        messages=[
            
            {"role": "user", "content": f"{prompt}"}]
    )   

    return chat_response.choices[0].message.content


prompt= f"""convert this pronunciation back to normal japanese: geɴ'iɴ?  sonna  fɯɯ ni ɕiɽoi hebi no geŋkakɯ ga, omae no ɕɯɯi ni naɴ do mo naɴ do mo aɽawaɽerɯ, kiʔkake na no ka naɴ na no ka? mi ni oboeʔtsɯ no ka? """

result= p2g(prompt)

print(result)
```


...or simply through HF transformers:

```python
from transformers import AutoModelForCausalLM, AutoTokenizer
device = "cuda" # the device to load the model onto

model = AutoModelForCausalLM.from_pretrained(
    "Respair/Japanese_Phoneme_to_Grapheme_LLM",
    torch_dtype="auto",
    device_map="auto"
)
tokenizer = AutoTokenizer.from_pretrained("Respair/Japanese_Phoneme_to_Grapheme_LLM")


tokenizer.pad_token = "<|endoftext|>"
tokenizer.bos_token = "<|endoftext|>"
tokenizer.eos_token = "<|im_end|>"
prompt = "convert this pronunciation back to normal japanese: geɴ'iɴ?  sonna  fɯɯ ni ɕiɽoi hebi no geŋkakɯ ga, omae no ɕɯɯi ni naɴ do mo naɴ do mo aɽawaɽerɯ, kiʔkake na no ka naɴ na no ka? mi ni oboeʔtsɯ no ka?"
# or anyother prompts, this model was trained on an instruction tuned dataset, so it should be a bit robust to variations in prompt


messages = [

    {"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
    messages,
    tokenize=False,
    add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    model_inputs.input_ids,

    pad_token_id=tokenizer.pad_token_id,
    bos_token_id=tokenizer.bos_token_id,
    eos_token_id=tokenizer.eos_token_id,

    temperature=0.1,
    max_new_tokens=512
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
response
```