A custom model is chosen or adapted for a particular task rather than used as a general-purpose assistant. For review classification, that might mean selecting a model already specialized in sentiment analysis or fine-tuning a model to return the required class labels. A smaller specialist can be a better fit than a powerful general model, but the right choice depends on output quality and processing cost for your task. section 8.0 section 9.10
There are two practical routes:
- Find an existing specialist. Filter Hugging Face models by task, inspect a model description, and try its sample interface. A sentiment model is one candidate for classifying reviews. section 8.4.1 section 8.4.2
- Use a fine-tuned model. Supply its model ID to the OpenAI client. If it has learned to map review text directly to a class, the input can be just the review rather than repeated task instructions and class labels. section 9.10
Classify a review
For an existing sentiment model, create a Transformers pipeline with `model='cardiffnlp/twitter-roberta-base-sentiment-latest'`, then pass it a review. The example input “This movie was really awful!” returns a negative label and a score. This illustrates a model selected for the job; it is not a model you trained yourself. section 8.4.2
The input matters. A general model given only a review may respond with commentary because it has not been told to classify it. In the reported fine-tuned review-classification example, the same short input produced class labels: accuracy was 70% versus 60% for the earlier version, with about 200 fewer tokens used. Test candidates on a sample of your own data rather than assuming those results will transfer. section 9.10 section 1.5.1
Listing 8.4 Sentiment classification using Hugging Face Transformers
import argparse
import transformers
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('review', type=str, help='Text of a review')
args = parser.parse_args()
sentiment_pipeline = transformers.pipeline( #1
model='cardiffnlp/twitter-roberta-base-sentiment-latest')
result = sentiment_pipeline(args.review) #2
print(result) #3
A complete Python example accepts a review, runs a named sentiment model through a Transformers pipeline, and prints the result. section 8.4.2
