Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -34,41 +34,36 @@ def principal(tweets):
|
|
34 |
tweet_list = [i.text for i in tweets]
|
35 |
text= pd.DataFrame(tweet_list)
|
36 |
text1=text[0].values
|
37 |
-
indices1=tokenizer.batch_encode_plus(text1.tolist(),
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
logits1 = outputs1[0]
|
68 |
-
# Move logits and labels to CPU
|
69 |
-
logits1 = logits1.detach().cpu().numpy()
|
70 |
-
# Store predictions and true labels
|
71 |
-
predictions.append(logits1)
|
72 |
flat_predictions = [item for sublist in predictions for item in sublist]
|
73 |
flat_predictions = np.argmax(flat_predictions, axis=1).flatten()#p = [i for i in classifier(tweet_list)]
|
74 |
df = pd.DataFrame(list(zip(tweet_list, flat_predictions)),columns =['Latest'+str(number_of_tweets)+'Tweets'+' on '+search_words, 'Sexista'])
|
|
|
34 |
tweet_list = [i.text for i in tweets]
|
35 |
text= pd.DataFrame(tweet_list)
|
36 |
text1=text[0].values
|
37 |
+
indices1=tokenizer.batch_encode_plus(text1.tolist(), max_length=128,add_special_tokens=True,return_attention_mask=True,pad_to_max_length=True,truncation=True)
|
38 |
+
input_ids1=indices1["input_ids"]
|
39 |
+
attention_masks1=indices1["attention_mask"]
|
40 |
+
prediction_inputs1= torch.tensor(input_ids1)
|
41 |
+
prediction_masks1 = torch.tensor(attention_masks1)
|
42 |
+
# Set the batch size.
|
43 |
+
batch_size = 25
|
44 |
+
# Create the DataLoader.
|
45 |
+
prediction_data1 = TensorDataset(prediction_inputs1, prediction_masks1)
|
46 |
+
prediction_sampler1 = SequentialSampler(prediction_data1)
|
47 |
+
prediction_dataloader1 = DataLoader(prediction_data1, sampler=prediction_sampler1, batch_size=batch_size)
|
48 |
+
print('Predicting labels for {:,} test sentences...'.format(len(prediction_inputs1)))
|
49 |
+
# Put model in evaluation mode
|
50 |
+
model.eval()
|
51 |
+
# Tracking variables
|
52 |
+
predictions = []
|
53 |
+
# Predict
|
54 |
+
for batch in prediction_dataloader1:
|
55 |
+
batch = tuple(t.to(device) for t in batch)
|
56 |
+
# Unpack the inputs from our dataloader
|
57 |
+
b_input_ids1, b_input_mask1 = batch
|
58 |
+
# Telling the model not to compute or store gradients, saving memory and # speeding up prediction
|
59 |
+
with torch.no_grad():
|
60 |
+
# Forward pass, calculate logit predictions
|
61 |
+
outputs1 = model(b_input_ids1, token_type_ids=None,attention_mask=b_input_mask1)
|
62 |
+
logits1 = outputs1[0]
|
63 |
+
# Move logits and labels to CPU
|
64 |
+
logits1 = logits1.detach().cpu().numpy()
|
65 |
+
# Store predictions and true labels
|
66 |
+
predictions.append(logits1)
|
|
|
|
|
|
|
|
|
|
|
67 |
flat_predictions = [item for sublist in predictions for item in sublist]
|
68 |
flat_predictions = np.argmax(flat_predictions, axis=1).flatten()#p = [i for i in classifier(tweet_list)]
|
69 |
df = pd.DataFrame(list(zip(tweet_list, flat_predictions)),columns =['Latest'+str(number_of_tweets)+'Tweets'+' on '+search_words, 'Sexista'])
|