Change gen output
Browse files
app.py
CHANGED
|
@@ -16,6 +16,7 @@ tokenizer = AutoTokenizer.from_pretrained(peft_model_id)
|
|
| 16 |
# Load the Lora model
|
| 17 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
| 18 |
|
|
|
|
| 19 |
|
| 20 |
def gen_entities(text):
|
| 21 |
text = f"<SP> text: {text}\n\n entities: "
|
|
@@ -23,7 +24,8 @@ def gen_entities(text):
|
|
| 23 |
with torch.cuda.amp.autocast():
|
| 24 |
output_tokens = model.generate(**batch, max_new_tokens=256, eos_token_id=50258)
|
| 25 |
|
| 26 |
-
return tokenizer.decode(output_tokens
|
|
|
|
| 27 |
|
| 28 |
|
| 29 |
iface = gr.Interface(fn=gen_entities, inputs="text", outputs="text")
|
|
|
|
| 16 |
# Load the Lora model
|
| 17 |
model = PeftModel.from_pretrained(model, peft_model_id)
|
| 18 |
|
| 19 |
+
model.eval()
|
| 20 |
|
| 21 |
def gen_entities(text):
|
| 22 |
text = f"<SP> text: {text}\n\n entities: "
|
|
|
|
| 24 |
with torch.cuda.amp.autocast():
|
| 25 |
output_tokens = model.generate(**batch, max_new_tokens=256, eos_token_id=50258)
|
| 26 |
|
| 27 |
+
# return tokenizer.decode(output_tokens, skip_special_tokens=False)
|
| 28 |
+
return tokenizer.batch_decode(output_tokens.detach().cpu().numpy(), skip_special_tokens=True)
|
| 29 |
|
| 30 |
|
| 31 |
iface = gr.Interface(fn=gen_entities, inputs="text", outputs="text")
|