Spaces:
Runtime error
Runtime error
Commit
·
b8b2797
1
Parent(s):
5c13be2
performance enhancement with torch autograd disabled
Browse files
app.py
CHANGED
@@ -9,9 +9,10 @@ lac = LAC(mode="seg")
|
|
9 |
|
10 |
def make_request(chinese_text):
|
11 |
tokenizer.src_lang="zh"
|
12 |
-
|
13 |
-
|
14 |
-
|
|
|
15 |
|
16 |
def generatepinyin(input):
|
17 |
pinyin_list = pinyin(input)
|
|
|
9 |
|
10 |
def make_request(chinese_text):
|
11 |
tokenizer.src_lang="zh"
|
12 |
+
with torch.no_grad():
|
13 |
+
encoded_zh = tokenizer(chinese_text, return_tensors="pt")
|
14 |
+
generated_tokens = model.generate(**encoded_zh, forced_bos_token_id=tokenizer.get_lang_id("en"))
|
15 |
+
return tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
|
16 |
|
17 |
def generatepinyin(input):
|
18 |
pinyin_list = pinyin(input)
|