subbunanepalli commited on
Commit
28fa488
·
verified ·
1 Parent(s): 9175e50

Create app/utils.py

Browse files
Files changed (1) hide show
  1. 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
+ }