amytran589-aus commited on
Commit
9bb2e82
1 Parent(s): 8557578

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +40 -0
README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: zero-shot-classification
3
+ ---
4
+ # Install transformers library
5
+ !pip install transformers
6
+
7
+ # Import necessary libraries
8
+ import pandas as pd
9
+ from transformers import pipeline
10
+ from google.colab import files
11
+
12
+ # Upload the file
13
+ uploaded = files.upload()
14
+
15
+ # Load the dataset
16
+ file_name = 'publications.csv' # Use the file name as uploaded
17
+ df = pd.read_csv(file_name)
18
+
19
+ # Display the first few rows of the dataset
20
+ df.head()
21
+
22
+ # Load the zero-shot classification pipeline
23
+ classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")
24
+
25
+ # Define the categories
26
+ candidate_labels = ["World", "Sports", "Business", "Science and Technology", "Entertainment", "Lifestyle"]
27
+
28
+ # Classify each news article
29
+ results = []
30
+
31
+ for article in df['headline']:
32
+ result = classifier(article, candidate_labels)
33
+ category = result['labels'][0]
34
+ results.append(category)
35
+
36
+ # Add the results to the DataFrame
37
+ df['category'] = results
38
+
39
+ # Display the categorized DataFrame
40
+ df.head(10)