brjoey commited on
Commit
68c0eb6
·
verified ·
1 Parent(s): e348dce

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -0
README.md CHANGED
@@ -25,6 +25,47 @@ Alongside these models, FinBERT, different versions of RoBERTa, and EconBERT wer
25
  ## How to use
26
 
27
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
28
  ```
29
  ---
30
  # Citation
 
25
  ## How to use
26
 
27
  ```python
28
+ import pandas as pd
29
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
30
+
31
+ # Load model and tokenizer
32
+ model_name = "brjoey/CBSI-bert-base-uncased"
33
+ classifier = pipeline(
34
+ "text-classification",
35
+ model=model_name,
36
+ tokenizer=model_name
37
+ )
38
+
39
+ # Define label mapping
40
+ cbsi_label_map = {
41
+ 0: "neutral",
42
+ 1: "dovish",
43
+ 2: "hawkish"
44
+ }
45
+
46
+ # Classify a column in a Pandas DataFrame - replace with your DataFrame
47
+ texts = [
48
+ "The Governing Council decided to lower interest rates.",
49
+ "The central bank will maintain its current policy stance."
50
+ ]
51
+
52
+ df = pd.DataFrame({
53
+ "text": texts
54
+ })
55
+
56
+ # Run classification
57
+ predictions = classifier(
58
+ df["text"].tolist()
59
+ )
60
+
61
+ # Store the results
62
+ df["label"], df["score"] = zip(*[
63
+ (cbsi_label_map[int(pred["label"].split("_")[-1])], pred["score"])
64
+ for pred in predictions
65
+ ])
66
+
67
+ print("\n === Results ===\n")
68
+ print(df[["text", "label", "score"]])
69
  ```
70
  ---
71
  # Citation