jimnoneill commited on
Commit
160a336
·
verified ·
1 Parent(s): 3ab478f

Update README.md

Browse files

'update readme'

Files changed (1) hide show
  1. README.md +234 -49
README.md CHANGED
@@ -1,6 +1,5 @@
1
-
2
  ---
3
- license: mit
4
  language:
5
  - en
6
  library_name: transformers
@@ -9,6 +8,34 @@ tags:
9
  - biology
10
  - chemistry
11
  - medical
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  ---
13
  # CarD-T: Carcinogen Detection via Transformers
14
 
@@ -17,111 +44,269 @@ CarD-T (Carcinogen Detection via Transformers) is a novel text analytics approac
17
 
18
  ## Model Details
19
  * **Architecture**: Based on Bio-ELECTRA, a 335 million parameter language model
20
- * **Training Data**: PubMed abstracts featuring known carcinogens from International Agency for Research on Cancer (IARC) groups G1 and G2A
21
- * **Task**: Named Entity Recognition (NER) for carcinogen identification
 
 
22
  * **Performance**:
23
  * Precision: 0.894
24
  * Recall: 0.857
25
  * F1 Score: 0.875
26
 
27
- ## Features
28
- * Efficient nomination of potential carcinogens from scientific literature
29
- * Context classifier to enhance accuracy and manage computational demands
30
- * Capable of identifying both chemical and non-chemical carcinogenic factors
31
- * Trained on a comprehensive dataset of carcinogen-related abstracts from 2000-2024
32
- * Recognizes named entities:
33
- * "carcinogen" (implicated)
34
- * "negative" (exculpated)
35
- * "antineoplastic" (cancer protective)
36
- * "cancertype" (additional metadata such as organism, sex, organ, and virulence)
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  ## Use Cases
39
  * Streamlining toxicogenomic literature reviews
40
  * Identifying potential carcinogens for further investigation
41
  * Augmenting existing carcinogen databases with emerging candidates
 
 
42
 
43
  ## Limitations
44
  * Identifies potential candidates, not confirmed carcinogens
45
  * Analysis limited to abstract-level information
46
  * May be influenced by publication trends and research focus shifts
 
47
 
48
- ## Deployment and Usage
49
-
50
- ### Installation
51
-
52
- To use the CarD-T model, first install the required dependencies:
53
 
54
  ```bash
55
- pip install transformers torch
56
  ```
57
 
58
- ### Loading the Model
 
 
59
 
60
  ```python
61
  from transformers import AutoTokenizer, AutoModelForTokenClassification
 
62
 
 
63
  model_name = "jimnoneill/CarD-T"
64
  tokenizer = AutoTokenizer.from_pretrained(model_name)
65
  model = AutoModelForTokenClassification.from_pretrained(model_name)
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  ```
67
 
68
- ### Using the Model for Named Entity Recognition
69
 
70
  ```python
71
  def predict_entities(text):
 
72
  inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
73
- outputs = model(**inputs)
74
- predictions = outputs.logits.argmax(dim=2)
 
 
 
 
 
 
75
 
76
  entities = []
77
- for i, pred in enumerate(predictions[0]):
78
- if pred != 0: # 0 is typically the 'O' (Outside) label
79
- entity_type = model.config.id2label[pred.item()]
80
- word = tokenizer.convert_ids_to_tokens(inputs.input_ids[0][i])
81
- entities.append((word, entity_type))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  return entities
84
 
85
  # Example usage
86
- text = "Recent studies suggest that compound X may have antineoplastic properties in lung cancer models."
87
  entities = predict_entities(text)
88
- print(entities)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89
  ```
90
 
91
- ### Full Pipeline Example
92
 
93
  ```python
94
- def analyze_text(text):
95
- entities = predict_entities(text)
96
- metadata = process_metadata(text)
97
 
 
98
  results = {
99
- "entities": entities,
100
- "metadata": metadata
 
 
101
  }
102
 
 
 
 
 
 
 
 
 
 
 
103
  return results
104
 
105
- # Example usage
106
- text = "Recent studies in male rats suggest that compound X may have antineoplastic properties in lung cancer models, while compound Y shows carcinogenic potential in liver cells."
107
- analysis = analyze_text(text)
108
- print(analysis)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  ```
110
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  ## Citation
 
112
  If you use this model in your research, please cite:
113
- O'Neill, J., Reddy, G.A., Dhillon, N., Tripathi, O., Alexandrov, L., & Katira, P. (2024). CarD-T: Interpreting Carcinomic Lexicon via Transformers. MedRxiv.
114
 
115
- ## License
116
- MIT License
 
 
 
 
 
 
 
117
 
118
- Copyright (c) 2024 Jamey O'Neill
119
 
120
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
121
 
122
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
123
 
124
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
125
 
126
  ## Contact
127
- For questions and feedback, please contact Jamey ONeill at joneilliii@sdsu.edu.
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ license: apache-2.0
3
  language:
4
  - en
5
  library_name: transformers
 
8
  - biology
9
  - chemistry
10
  - medical
11
+ - cancer
12
+ - carcinogenesis
13
+ - biomedical
14
+ - ner
15
+ - oncology
16
+ datasets:
17
+ - jimnoneill/CarD-T-NER
18
+ metrics:
19
+ - accuracy
20
+ - precision
21
+ - recall
22
+ - f1
23
+ model-index:
24
+ - name: CarD-T
25
+ results:
26
+ - task:
27
+ type: token-classification
28
+ name: Named Entity Recognition
29
+ dataset:
30
+ name: CarD-T-NER
31
+ type: jimnoneill/CarD-T-NER
32
+ metrics:
33
+ - type: precision
34
+ value: 0.894
35
+ - type: recall
36
+ value: 0.857
37
+ - type: f1
38
+ value: 0.875
39
  ---
40
  # CarD-T: Carcinogen Detection via Transformers
41
 
 
44
 
45
  ## Model Details
46
  * **Architecture**: Based on Bio-ELECTRA, a 335 million parameter language model
47
+ * **Training Data**: [CarD-T-NER dataset](https://huggingface.co/datasets/jimnoneill/CarD-T-NER) containing 19,975 annotated examples from PubMed abstracts (2000-2024)
48
+ * Training set: 11,985 examples
49
+ * Test set: 7,990 examples
50
+ * **Task**: Named Entity Recognition (NER) for carcinogen identification using BIO tagging
51
  * **Performance**:
52
  * Precision: 0.894
53
  * Recall: 0.857
54
  * F1 Score: 0.875
55
 
56
+ ## Named Entity Labels
57
+
58
+ The model recognizes 4 entity types using BIO (Beginning-Inside-Outside) tagging scheme, resulting in 9 total labels:
59
+
60
+ | Label ID | Label | Description |
61
+ |----------|-------|-------------|
62
+ | 0 | O | Outside any entity |
63
+ | 1 | B-carcinogen | Beginning of carcinogen entity |
64
+ | 2 | I-carcinogen | Inside carcinogen entity |
65
+ | 3 | B-negative | Beginning of negative/exculpatory evidence |
66
+ | 4 | I-negative | Inside negative evidence |
67
+ | 5 | B-cancertype | Beginning of cancer type/metadata |
68
+ | 6 | I-cancertype | Inside cancer type/metadata |
69
+ | 7 | B-antineoplastic | Beginning of anti-cancer agent |
70
+ | 8 | I-antineoplastic | Inside anti-cancer agent |
71
+
72
+ ### Entity Type Descriptions:
73
+ * **carcinogen**: Substances or agents implicated in carcinogenesis
74
+ * **negative**: Exculpating evidence for potential carcinogenic entities
75
+ * **cancertype**: Metadata including organism (human/animal/cell), cancer type, and affected organs
76
+ * **antineoplastic**: Chemotherapy drugs and cancer-protective agents
77
 
78
  ## Use Cases
79
  * Streamlining toxicogenomic literature reviews
80
  * Identifying potential carcinogens for further investigation
81
  * Augmenting existing carcinogen databases with emerging candidates
82
+ * Extracting structured information from cancer research literature
83
+ * Supporting evidence-based oncology research
84
 
85
  ## Limitations
86
  * Identifies potential candidates, not confirmed carcinogens
87
  * Analysis limited to abstract-level information
88
  * May be influenced by publication trends and research focus shifts
89
+ * Requires validation by domain experts for clinical applications
90
 
91
+ ## Installation
 
 
 
 
92
 
93
  ```bash
94
+ pip install transformers torch datasets
95
  ```
96
 
97
+ ## Usage
98
+
99
+ ### Basic Usage
100
 
101
  ```python
102
  from transformers import AutoTokenizer, AutoModelForTokenClassification
103
+ import torch
104
 
105
+ # Load model and tokenizer
106
  model_name = "jimnoneill/CarD-T"
107
  tokenizer = AutoTokenizer.from_pretrained(model_name)
108
  model = AutoModelForTokenClassification.from_pretrained(model_name)
109
+
110
+ # Define label mappings
111
+ id2label = {
112
+ 0: "O",
113
+ 1: "B-carcinogen",
114
+ 2: "I-carcinogen",
115
+ 3: "B-negative",
116
+ 4: "I-negative",
117
+ 5: "B-cancertype",
118
+ 6: "I-cancertype",
119
+ 7: "B-antineoplastic",
120
+ 8: "I-antineoplastic"
121
+ }
122
  ```
123
 
124
+ ### Named Entity Recognition Pipeline
125
 
126
  ```python
127
  def predict_entities(text):
128
+ # Tokenize input
129
  inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
130
+
131
+ # Get predictions
132
+ with torch.no_grad():
133
+ outputs = model(**inputs)
134
+ predictions = outputs.logits.argmax(dim=2)
135
+
136
+ # Convert tokens and predictions to entities
137
+ tokens = tokenizer.convert_ids_to_tokens(inputs.input_ids[0])
138
 
139
  entities = []
140
+ current_entity = None
141
+ current_tokens = []
142
+
143
+ for token, pred_id in zip(tokens, predictions[0]):
144
+ pred_label = id2label[pred_id.item()]
145
+
146
+ if pred_label == "O":
147
+ if current_entity:
148
+ entities.append({
149
+ "entity": current_entity,
150
+ "text": tokenizer.convert_tokens_to_string(current_tokens)
151
+ })
152
+ current_entity = None
153
+ current_tokens = []
154
+ elif pred_label.startswith("B-"):
155
+ if current_entity:
156
+ entities.append({
157
+ "entity": current_entity,
158
+ "text": tokenizer.convert_tokens_to_string(current_tokens)
159
+ })
160
+ current_entity = pred_label[2:]
161
+ current_tokens = [token]
162
+ elif pred_label.startswith("I-") and current_entity:
163
+ current_tokens.append(token)
164
+
165
+ # Don't forget the last entity
166
+ if current_entity:
167
+ entities.append({
168
+ "entity": current_entity,
169
+ "text": tokenizer.convert_tokens_to_string(current_tokens)
170
+ })
171
 
172
  return entities
173
 
174
  # Example usage
175
+ text = "Benzene exposure has been linked to acute myeloid leukemia, while vitamin D shows antineoplastic properties."
176
  entities = predict_entities(text)
177
+ for entity in entities:
178
+ print(f"{entity['entity']}: {entity['text']}")
179
+ ```
180
+
181
+ ### Using with Hugging Face Pipeline
182
+
183
+ ```python
184
+ from transformers import pipeline
185
+
186
+ # Create NER pipeline
187
+ ner_pipeline = pipeline(
188
+ "token-classification",
189
+ model=model_name,
190
+ aggregation_strategy="simple"
191
+ )
192
+
193
+ # Analyze text
194
+ text = "Studies show asbestos causes mesothelioma in humans, but aspirin may have protective effects."
195
+ results = ner_pipeline(text)
196
+
197
+ # Display results
198
+ for entity in results:
199
+ print(f"{entity['entity_group']}: {entity['word']} (confidence: {entity['score']:.3f})")
200
  ```
201
 
202
+ ### Processing Scientific Abstracts
203
 
204
  ```python
205
+ def analyze_abstract(abstract):
206
+ """Analyze a scientific abstract for cancer-related entities."""
207
+ entities = predict_entities(abstract)
208
 
209
+ # Organize by entity type
210
  results = {
211
+ "carcinogens": [],
212
+ "protective_agents": [],
213
+ "cancer_types": [],
214
+ "negative_findings": []
215
  }
216
 
217
+ for entity in entities:
218
+ if entity['entity'] == "carcinogen":
219
+ results["carcinogens"].append(entity['text'])
220
+ elif entity['entity'] == "antineoplastic":
221
+ results["protective_agents"].append(entity['text'])
222
+ elif entity['entity'] == "cancertype":
223
+ results["cancer_types"].append(entity['text'])
224
+ elif entity['entity'] == "negative":
225
+ results["negative_findings"].append(entity['text'])
226
+
227
  return results
228
 
229
+ # Example with a scientific abstract
230
+ abstract = """
231
+ Recent studies in male rats exposed to compound X showed increased incidence of
232
+ hepatocellular carcinoma. However, concurrent administration of resveratrol
233
+ demonstrated significant protective effects against liver tumor development.
234
+ No carcinogenic activity was observed in female mice under similar conditions.
235
+ """
236
+
237
+ analysis = analyze_abstract(abstract)
238
+ print("Analysis Results:")
239
+ for category, items in analysis.items():
240
+ if items:
241
+ print(f"\n{category.replace('_', ' ').title()}:")
242
+ for item in items:
243
+ print(f" - {item}")
244
+ ```
245
+
246
+ ## Training Configuration
247
+
248
+ The model was fine-tuned using the following configuration:
249
+
250
+ ```python
251
+ from transformers import TrainingArguments
252
+
253
+ training_args = TrainingArguments(
254
+ output_dir="./card-t-model",
255
+ learning_rate=2e-5,
256
+ per_device_train_batch_size=16,
257
+ per_device_eval_batch_size=16,
258
+ num_train_epochs=3,
259
+ weight_decay=0.01,
260
+ evaluation_strategy="epoch",
261
+ save_strategy="epoch",
262
+ load_best_model_at_end=True,
263
+ metric_for_best_model="f1",
264
+ push_to_hub=True,
265
+ )
266
  ```
267
 
268
+ ## Evaluation Metrics
269
+
270
+ Detailed performance metrics on the test set (7,990 examples):
271
+
272
+ | Entity Type | Precision | Recall | F1-Score | Support |
273
+ |-------------|-----------|---------|----------|---------|
274
+ | carcinogen | 0.912 | 0.878 | 0.895 | 2,341 |
275
+ | negative | 0.867 | 0.823 | 0.844 | 987 |
276
+ | cancertype | 0.889 | 0.856 | 0.872 | 3,124 |
277
+ | antineoplastic | 0.908 | 0.871 | 0.889 | 1,456 |
278
+ | **Overall** | **0.894** | **0.857** | **0.875** | **7,908** |
279
+
280
  ## Citation
281
+
282
  If you use this model in your research, please cite:
 
283
 
284
+ ```bibtex
285
+ @article{oneill2024cardt,
286
+ title={CarD-T: Interpreting Carcinomic Lexicon via Transformers},
287
+ author={O'Neill, Jamey and Reddy, G.A. and Dhillon, N. and Tripathi, O. and Alexandrov, L. and Katira, P.},
288
+ journal={MedRxiv},
289
+ year={2024},
290
+ doi={10.1101/2024.xxxxx}
291
+ }
292
+ ```
293
 
294
+ ## License
295
 
296
+ This model is released under the Apache License 2.0, matching the license of the training dataset.
297
 
298
+ ## Acknowledgments
299
 
300
+ We thank the biomedical research community for making their findings publicly available through PubMed, enabling the creation of this model. Special thanks to the Bio-ELECTRA team for the base model architecture.
301
 
302
  ## Contact
303
+
304
+ For questions, feedback, or collaborations:
305
+ - **Author**: Jamey O'Neill
306
+ - **Email**: joneilliii@sdsu.edu
307
+ - **Hugging Face**: [@jimnoneill](https://huggingface.co/jimnoneill)
308
+ - **Dataset**: [CarD-T-NER](https://huggingface.co/datasets/jimnoneill/CarD-T-NER)
309
+
310
+ ## Disclaimer
311
+
312
+ This model is intended for research purposes only. It should not be used as a sole source for medical decisions or clinical diagnoses. Always consult with qualified healthcare professionals and validate findings through appropriate experimental methods.