Akjava commited on
Commit
1c197e3
Β·
verified Β·
1 Parent(s): 4bdf72f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -62,6 +62,29 @@ llm_model = None
62
 
63
  def trans(text):
64
  text = "こんにけは"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
 
66
  # γƒ†γ‚­γ‚Ήγƒˆγ«θ¨€θͺžγ‚Ώγ‚°γ‚’δ»˜δΈŽγ—γ€γƒγ‚€γƒˆεˆ—γ«ε€‰ζ›
67
  input_text = f"<2ja>{text}".encode('utf-8')
 
62
 
63
  def trans(text):
64
  text = "こんにけは"
65
+
66
+ # γƒ†γ‚­γ‚Ήγƒˆγ«θ¨€θͺžγ‚Ώγ‚°γ‚’δ»˜δΈŽγ—γ€γƒγ‚€γƒˆεˆ—γ«ε€‰ζ›
67
+ input_text = f"<2ja>{text}".encode('utf-8')
68
+
69
+ # γƒˆγƒΌγ‚―γƒŠγ‚€γ‚Ί
70
+ tokens = llm.tokenize(input_text)
71
+ print("Tokens:", tokens)
72
+
73
+ # BOSγƒˆγƒΌγ‚―γƒ³γ‚’ε–εΎ—γ—γ€η’Ίθͺ
74
+ bos_token = llm.token_bos()
75
+ print("BOS Token:", bos_token)
76
+ initial_tokens = [bos_token]
77
+ print("Initial Tokens:", initial_tokens)
78
+
79
+ # η”Ÿζˆ
80
+ buf = ""
81
+ for token in llm.generate(initial_tokens, top_p=0.95, temp=0.0, repeat_penalty=1.0):
82
+ decoded = llm.detokenize([token]).decode('utf-8', errors='ignore')
83
+ buf += decoded
84
+ if token == llm.token_eos():
85
+ break
86
+
87
+ return buf
88
 
89
  # γƒ†γ‚­γ‚Ήγƒˆγ«θ¨€θͺžγ‚Ώγ‚°γ‚’δ»˜δΈŽγ—γ€γƒγ‚€γƒˆεˆ—γ«ε€‰ζ›
90
  input_text = f"<2ja>{text}".encode('utf-8')