goatley commited on
Commit
85dd36d
1 Parent(s): 5f45941

Upload 3 files

Browse files
Files changed (3) hide show
  1. instructions +64 -0
  2. requirements.txt +2 -0
  3. text_analysis.py +25 -0
instructions ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Project Description
2
+ ## The sentiment analysis project utilizes the distilbert-base-uncased model from Hugging Face to perform sentiment classification on text inputs. It demonstrates how to leverage pre-trained models for natural language processing tasks using the Transformers library.
3
+
4
+ # Installation Instructions
5
+ ## To set up the project on your GitHub repository and enable others to run your sentiment analysis script, follow these steps:
6
+
7
+ ## Clone Your Repository
8
+ ## If you haven't already cloned your GitHub repository to your local machine, do so using Git commands. Open your Gitpod terminal and navigate to the directory where you want to clone your repository:
9
+
10
+ git clone <your-github-repository-url>
11
+ cd <repository-name>
12
+
13
+ ## Install Dependencies
14
+ Ensure you have Python installed. You'll also need the transformers library from Hugging Face for this project. Install it and other dependencies using pip:
15
+
16
+ pip install transformers
17
+
18
+ ## Download the Script
19
+ Download or create your text_analysis.py script and place it in the root directory of your repository.
20
+
21
+ ## Set Up Your Environment
22
+ Set up your Python environment and ensure all necessary packages are installed:
23
+
24
+ python -m venv venv # Create a virtual environment (optional but recommended)
25
+ source venv/bin/activate # Activate the virtual environment (Linux/Mac)
26
+ # or
27
+ venv\Scripts\activate # Activate the virtual environment (Windows)
28
+ pip install -r requirements.txt # Install required packages (if you have a requirements file)
29
+
30
+ # Usage Examples
31
+ Here are examples of how to use the sentiment analysis script (text_analysis.py) with different text inputs:
32
+
33
+ # Import necessary libraries
34
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
35
+
36
+ # Load tokenizer and model
37
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
38
+ model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
39
+
40
+ # Create a pipeline for sentiment analysis
41
+ nlp_pipeline = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
42
+
43
+ # Example texts for analysis
44
+ texts = [
45
+ "I love using Hugging Face models!",
46
+ "This movie was terrible.",
47
+ "The weather today is nice.",
48
+ "I am feeling neutral about this.",
49
+ "The product exceeded my expectations."
50
+ ]
51
+
52
+ # Perform sentiment analysis for each text
53
+ for text in texts:
54
+ print(f"Text: {text}")
55
+ result = nlp_pipeline(text)
56
+ print(f"Sentiment: {result}\n")
57
+
58
+ # Credits
59
+ Include acknowledgments for libraries used and any data sources:
60
+
61
+ Transformers Library: Used for loading and utilizing the distilbert-base-uncased model.
62
+ Hugging Face Model Hub: Source of the pre-trained model checkpoint.
63
+ Python: Programming language used for scripting.
64
+ GitHub: Hosting platform for version control and project collaboration.
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ transformers
2
+ torch
text_analysis.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Import necessary libraries
2
+ from transformers import pipeline, AutoTokenizer, AutoModelForSequenceClassification
3
+
4
+ # Load tokenizer and model
5
+ tokenizer = AutoTokenizer.from_pretrained("distilbert-base-uncased")
6
+ model = AutoModelForSequenceClassification.from_pretrained("distilbert-base-uncased")
7
+
8
+ # Create a pipeline for sentiment analysis
9
+ nlp_pipeline = pipeline('sentiment-analysis', model=model, tokenizer=tokenizer)
10
+
11
+ # Example texts for analysis
12
+ texts = [
13
+ "I love using Hugging Face models!",
14
+ "This movie was terrible.",
15
+ "The weather today is nice.",
16
+ "I am feeling neutral about this.",
17
+ "The product exceeded my expectations."
18
+ "I love my life"
19
+ ]
20
+
21
+ # Perform sentiment analysis for each text
22
+ for text in texts:
23
+ print(f"Text: {text}")
24
+ result = nlp_pipeline(text)
25
+ print(f"Sentiment: {result}\n")