Categories / README.md
amytran589-aus's picture
Create README.md
9bb2e82 verified
metadata
pipeline_tag: zero-shot-classification

Install transformers library

!pip install transformers

Import necessary libraries

import pandas as pd from transformers import pipeline from google.colab import files

Upload the file

uploaded = files.upload()

Load the dataset

file_name = 'publications.csv' # Use the file name as uploaded df = pd.read_csv(file_name)

Display the first few rows of the dataset

df.head()

Load the zero-shot classification pipeline

classifier = pipeline("zero-shot-classification", model="facebook/bart-large-mnli")

Define the categories

candidate_labels = ["World", "Sports", "Business", "Science and Technology", "Entertainment", "Lifestyle"]

Classify each news article

results = []

for article in df['headline']: result = classifier(article, candidate_labels) category = result['labels'][0] results.append(category)

Add the results to the DataFrame

df['category'] = results

Display the categorized DataFrame

df.head(10)