Views
No views yet
pip install lowerated1from lowerated.rate.entity import Entity
2
3# Example usage
4if __name__ == "__main__":
5 some_movie_reviews = [
6 "bad movie!", "worse than other movies.", "bad.",
7 "best movie", "very good movie", "the cinematography was insane",
8 "story was so beautiful", "the emotional element was missing but cinematography was great",
9 "didn't feel a thing watching this",
10 "oooof, eliot and jessie were so good. the casting was the best",
11 "yo who designed the set, that was really good",
12 "such stories are rare to find"
13 ]
14
15 # Create entity object (loads the whole pipeline)
16 # list of aspects. ('Cinematography', 'Direction', 'Story', 'Characters', 'Production Design', 'Unique Concept', 'Emotions')
17 entity = Entity(name="Movie")
18
19 rating = entity.rate(reviews=some_movie_reviews)
20
21 print("LM6: ", rating["LM6"])1import torch
2from transformers import DebertaV2ForSequenceClassification, DebertaV2Tokenizer
3
4# Load the fine-tuned model and tokenizer
5model = DebertaV2ForSequenceClassification.from_pretrained('Lowerated/deberta-v3-lm6')
6tokenizer = DebertaV2Tokenizer.from_pretrained('Lowerated/deberta-v3-lm6')
7
8# Ensure the model is in evaluation mode
9model.eval()
10
11# Define the label mapping
12label_columns = ['Cinematography', 'Direction', 'Story', 'Characters', 'Production Design', 'Unique Concept', 'Emotions']
13
14# Function for predicting sentiment scores
15def predict_sentiment(review):
16 # Tokenize the input review
17 inputs = tokenizer(review, return_tensors='pt', truncation=True, padding=True)
18
19 # Disable gradient calculations for inference
20 with torch.no_grad():
21 # Get model outputs
22 outputs = model(**inputs)
23
24 # Get the prediction logits
25 predictions = outputs.logits.squeeze().detach().numpy()
26 return predictions
27
28# Function to print predictions with labels
29def print_predictions(review, predictions):
30 print(f"Review: {review}")
31 for label, score in zip(label_columns, predictions):
32 print(f"{label}: {score:.2f}")
33
34
35review = "The cinematography was stunning, but the story was weak."
36predictions = predict_sentiment(review)
37print_predictions(review, predictions)
381{
2'eval_loss': 0.04379426687955856,
3 'eval_model_preparation_time': 0.0016,
4 'eval_accuracy': 0.9845067801235796,
5 'eval_f1': 0.7419,
6 'eval_precision': 0.6831499999999999,
7 'eval_recall': 0.86185,
8 'eval_runtime': 2014.0076,
9 'eval_samples_per_second': 29.451,
10 'eval_steps_per_second': 3.682
11}original review: the story was amazing but the cinematography wasn't it
Cinematography: ["the cinematography wasn't"]
Direction: []
Story: ['the story was amazing']
Characters: []
Production Design: []
Unique Concept: []
Emotions: []1@model{lm6-movie-aspect-extraction-bert,
2 author = {LOWERATED},
3 title = {lm6-movie-aspect-extraction-bert},
4 year = {2024},
5 url = {https://huggingface.coLowerated/lm6-movie-aspect-extraction-bert},
6}