minemaster01 commited on
Commit
142cc53
·
verified ·
1 Parent(s): 03d2b1d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +1 -24
app.py CHANGED
@@ -56,29 +56,6 @@ model = model.to(device)
56
  model.eval()
57
 
58
  # Inference function
59
- def get_word_classifications(text):
60
- text = " ".join(text.split(" ")[:2048])
61
- inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
62
- inputs = {k: v.to(device) for k, v in inputs.items()}
63
- tokens = tokenizer.convert_ids_to_tokens(inputs["input_ids"][0])
64
- with torch.no_grad():
65
- tags, _ = model(input_ids=inputs["input_ids"], attention_mask=inputs["attention_mask"])
66
- word_tags = []
67
- current_word = ""
68
- current_tag = ""
69
- for token, tag in zip(tokens, tags[0]):
70
- if token in ["<s>", "</s>"]:
71
- continue
72
- if token.startswith("▁"):
73
- if current_word:
74
- word_tags.append(str(current_tag))
75
- current_word = token[1:] if token != "▁" else ""
76
- current_tag = tag
77
- else:
78
- current_word += token
79
- if current_word:
80
- word_tags.append(str(current_tag))
81
- return word_tags
82
 
83
  def get_word_probabilities(text):
84
  text = " ".join(text.split(" ")[:2048])
@@ -172,7 +149,7 @@ def setup_hf_dataset():
172
 
173
  # Main inference + logging function
174
  def infer_and_log(text_input):
175
- word_tags = get_word_classifications(text_input)
176
  timestamp = datetime.datetime.now().isoformat()
177
  submission_id = str(uuid.uuid4())
178
 
 
56
  model.eval()
57
 
58
  # Inference function
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  def get_word_probabilities(text):
61
  text = " ".join(text.split(" ")[:2048])
 
149
 
150
  # Main inference + logging function
151
  def infer_and_log(text_input):
152
+ word_tags = get_word_probabilities(text_input)
153
  timestamp = datetime.datetime.now().isoformat()
154
  submission_id = str(uuid.uuid4())
155