boltuix commited on
Commit
7d47c04
·
verified ·
1 Parent(s): 2ed5136

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +17 -4
README.md CHANGED
@@ -103,23 +103,36 @@ Use the model for NER with the following Python code:
103
 
104
  ```python
105
  from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
 
 
106
 
107
  # Load model and tokenizer
108
  tokenizer = AutoTokenizer.from_pretrained("boltuix/EntityBERT")
109
  model = AutoModelForTokenClassification.from_pretrained("boltuix/EntityBERT")
110
 
111
- # Create NER pipeline
112
  nlp = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
113
 
114
  # Input text
115
- text = "Dr. Sarah Lee at Johns Hopkins, Baltimore, MD, books a flight to Rochester, MN on July 10, 2025, contact +1-410-955-5000 or [email protected], visit www.airmed.com."
 
 
116
 
117
  # Run inference
118
  ner_results = nlp(text)
119
 
120
- # Print results
 
121
  for entity in ner_results:
122
- print(f"{entity['word']:15} -> {entity['entity']}")
 
 
 
 
 
 
 
 
123
  ```
124
 
125
  ### ✨ Example Output
 
103
 
104
  ```python
105
  from transformers import AutoTokenizer, AutoModelForTokenClassification, pipeline
106
+ import json
107
+ from collections import defaultdict
108
 
109
  # Load model and tokenizer
110
  tokenizer = AutoTokenizer.from_pretrained("boltuix/EntityBERT")
111
  model = AutoModelForTokenClassification.from_pretrained("boltuix/EntityBERT")
112
 
113
+ # Create NER pipeline with aggregation
114
  nlp = pipeline("token-classification", model=model, tokenizer=tokenizer, aggregation_strategy="simple")
115
 
116
  # Input text
117
+ text = (
118
+ "Plan a trip to Miami from Orlando"
119
+ )
120
 
121
  # Run inference
122
  ner_results = nlp(text)
123
 
124
+ # Organize into dictionary by entity_group
125
+ entities = defaultdict(list)
126
  for entity in ner_results:
127
+ group = entity["entity_group"]
128
+ word = entity["word"]
129
+ entities[group].append(word)
130
+
131
+ # Format results into final JSON structure
132
+ formatted_output = {k: " ".join(v) for k, v in entities.items()}
133
+
134
+ # Pretty-print as JSON
135
+ print(json.dumps(formatted_output, indent=2))
136
  ```
137
 
138
  ### ✨ Example Output