ProfessorLeVesseur commited on
Commit
35a3d83
·
verified ·
1 Parent(s): 98720b7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +27 -14
README.md CHANGED
@@ -90,16 +90,6 @@ While the model performs well on the provided dataset, it may not generalize to
90
 
91
  ## How to Use 🚀
92
 
93
- ```python
94
- from transformers import pipeline
95
-
96
- classifier = pipeline("text-classification", model="ProfessorLeVesseur/bert-base-cased-timeframe-classifier")
97
- result = classifier("The meeting will take place tomorrow.")
98
- print(result)
99
- ```
100
-
101
- ## How to Use 🚀
102
-
103
  This model can be used for text classification tasks, either for individual text inputs or for batch processing via a DataFrame. Below are examples of both use cases.
104
 
105
  ### Classifying Input Text
@@ -114,9 +104,32 @@ classifier = pipeline(
114
  "text-classification", # Specify the task type as text classification
115
  model="ProfessorLeVesseur/bert-base-cased-timeframe-classifier" # Specify the model to use from the Hugging Face Model Hub
116
  )
117
-
118
- # Use the classifier to predict the label for the input text
119
  result = classifier("MTSS.ai is the future of education, call it education².") # Classify the input text and store the result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120
 
121
- # Print the classification result, which includes the predicted label and the confidence score
122
- print(result) # Output the result to the console
 
 
90
 
91
  ## How to Use 🚀
92
 
 
 
 
 
 
 
 
 
 
 
93
  This model can be used for text classification tasks, either for individual text inputs or for batch processing via a DataFrame. Below are examples of both use cases.
94
 
95
  ### Classifying Input Text
 
104
  "text-classification", # Specify the task type as text classification
105
  model="ProfessorLeVesseur/bert-base-cased-timeframe-classifier" # Specify the model to use from the Hugging Face Model Hub
106
  )
 
 
107
  result = classifier("MTSS.ai is the future of education, call it education².") # Classify the input text and store the result
108
+ print(result) # Output the result
109
+ ```
110
+
111
+ ### Classifying Text in a DataFrame
112
+
113
+ For batch processing, you can classify multiple text entries stored in a DataFrame. This example demonstrates how to read a CSV file and add a new column with the predicted labels:
114
+
115
+ ```python
116
+ # Import libraries
117
+ from transformers import pipeline # Import the pipeline function from the transformers library
118
+ import pandas as pd # Import pandas for data manipulation
119
+
120
+ # Read the CSV file
121
+ file_path = 'filename.csv' # Define the path to the CSV file
122
+ df = pd.read_csv(file_path) # Read the CSV file into a DataFrame
123
+
124
+ # Initialize the text classification pipeline
125
+ classifier = pipeline(
126
+ "text-classification", # Specify the task type as text classification
127
+ model="ProfessorLeVesseur/bert-base-cased-timeframe-classifier" # Specify the model to use from the Hugging Face Model Hub
128
+ )
129
+
130
+ # Apply the classifier to each row in the "Text" column and store results in a new column "label"
131
+ df['label'] = df['Text'].apply(lambda text: classifier(text)[0]['label']) # Classify each text and store the label
132
 
133
+ # Display the DataFrame with the new "label" column
134
+ df.head(5) # Display the first 5 rows of the DataFrame
135
+ ```