Spaces:
Sleeping
Sleeping
| import torch | |
| import numpy as np | |
| def model_predict(model, tokenizer, sentences): | |
| """ | |
| Predict the labels of the sentences using the model and tokenizer | |
| Args: | |
| model: Model (transformers) | |
| tokenizer: Tokenizer (transformers tokenizer) | |
| sentences: Sentences to predict (ndarray) | |
| Returns: | |
| predictions: Predicted labels | |
| """ | |
| inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors="pt", max_length=512).to("cpu") | |
| # Classify sentences | |
| with torch.no_grad(): | |
| outputs = model(**inputs) # get the logits | |
| label = np.argmax(outputs.logits.to("cpu")) | |
| return int(label) |