Views
No views yet
dslim/bert-base-NER for detecting vessels (ships) and organizations in maritime news articles and documents.dslim/bert-base-NER| Text | Detected Entities |
|---|---|
| "The fishing vessel Hai Feng 718 was detained by authorities." | Hai Feng 718 (VESSEL: 1.00) |
| "Coast guard seized the trawler Thunder near disputed waters." | Thunder (VESSEL: 1.00) |
| "Pacific Seafood Inc. announced quarterly earnings today." | Pacific Seafood Inc (ORG: 0.95) |
| "The vessel Thunder owned by Pacific Seafood Inc. was seized." | Thunder (VESSEL: 1.00), Pacific Seafood Inc (ORG: 0.98) |
dslim/bert-base-NER1TrainingArguments(
2 num_train_epochs=3,
3 per_device_train_batch_size=32,
4 learning_rate=2e-5,
5 weight_decay=0.01,
6 max_length=128,
7 fp16=True
8)1from transformers import pipeline
2
3# Load the model
4ner = pipeline("ner", model="your-username/bert-vessel-ner", aggregation_strategy="simple")
5
6# Example 1: Vessel detection
7text = "The fishing vessel Hai Feng 718 was detained by authorities."
8entities = ner(text)
9for entity in entities:
10 print(f"{entity['word']} -> {entity['entity_group']} ({entity['score']:.2f})")
11# Output: Hai Feng 718 -> MISC (1.00) # MISC = VESSEL
12
13# Example 2: Mixed entities
14text = "The vessel Thunder owned by Pacific Seafood Inc. was seized."
15entities = ner(text)
16for entity in entities:
17 print(f"{entity['word']} -> {entity['entity_group']} ({entity['score']:.2f})")
18# Output:
19# Thunder -> MISC (1.00) # VESSEL
20# Pacific Seafood Inc -> ORG (0.98) # Organization1from transformers import AutoTokenizer, AutoModelForTokenClassification
2import torch
3
4# Load model and tokenizer
5model = AutoModelForTokenClassification.from_pretrained("your-username/bert-vessel-ner")
6tokenizer = AutoTokenizer.from_pretrained("your-username/bert-vessel-ner")
7
8# Tokenize and predict
9text = "The vessel Thunder was seized."
10inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
11
12with torch.no_grad():
13 outputs = model(**inputs)
14 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
15 predicted_ids = torch.argmax(predictions, dim=-1)
16
17# Decode predictions
18tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0])
19for token, pred_id in zip(tokens, predicted_ids[0]):
20 if token not in ['[CLS]', '[SEP]', '[PAD]']:
21 label = model.config.id2label[pred_id.item()]
22 print(f"{token}: {label}")1entities = ner(text)
2for entity in entities:
3 # Rename MISC to VESSEL for clarity
4 if entity['entity_group'] == 'MISC':
5 entity['entity_group'] = 'VESSEL'
6 print(f"{entity['word']} -> {entity['entity_group']}")| Entity Type | Precision | Recall | F1 |
|---|---|---|---|
| VESSEL (MISC) | 1.0000 | 1.0000 | 1.0000 |
| ORG | 1.0000 | 1.0000 | 1.0000 |
1@misc{bert-vessel-ner,
2 title={BERT-NER Vessel Detection Model},
3 author={Your Name},
4 year={2025},
5 howpublished={\url{https://huggingface.co/your-username/bert-vessel-ner}}
6}dslim/bert-base-NER.