Spaces:
Runtime error
Runtime error
Create app/utils.py
Browse files- app/app/utils.py +14 -0
app/app/utils.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
|
| 3 |
+
def preprocess(text, tokenizer, max_len=128):
|
| 4 |
+
encoding = tokenizer(
|
| 5 |
+
text,
|
| 6 |
+
padding="max_length",
|
| 7 |
+
truncation=True,
|
| 8 |
+
max_length=max_len,
|
| 9 |
+
return_tensors="pt"
|
| 10 |
+
)
|
| 11 |
+
return {
|
| 12 |
+
"input_ids": encoding["input_ids"],
|
| 13 |
+
"attention_mask": encoding["attention_mask"]
|
| 14 |
+
}
|