Views
No views yet
| Metric | Score | Status |
|---|---|---|
| F1 Score | 90.87% | ✅ Excellent |
| Precision | 91.44% | ✅ High |
| Recall | 90.81% | ✅ High |
| Training Loss | 0.2604 | ✅ Low |
B- (Beginning): Start of an entityI- (Inside): Continuation of an entityO (Outside): Non-entity tokens1from transformers import AutoTokenizer, AutoModelForTokenClassification
2import torch
3
4# Load model and tokenizer
5model_name = "yashpwr/resume-ner-bert-v2"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForTokenClassification.from_pretrained(model_name)
8
9# Example resume text
10text = "John Smith is a senior software engineer with 8 years of experience at Google. He has expertise in Python, JavaScript, and machine learning. Contact: john.smith@gmail.com"
11
12# Tokenize
13inputs = tokenizer(
14 text,
15 return_tensors="pt",
16 truncation=True,
17 max_length=128,
18 padding=True
19)
20
21# Predict
22with torch.no_grad():
23 outputs = model(**inputs)
24 predictions = torch.argmax(outputs.logits, dim=2)
25
26# Extract entities
27entities = []
28current_entity = None
29
30for i, pred in enumerate(predictions[0]):
31 label = model.config.id2label[pred.item()]
32 token = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0][i])
33
34 if label.startswith('B-'):
35 if current_entity:
36 entities.append(current_entity)
37 current_entity = {
38 'text': token,
39 'label': label[2:], # Remove 'B-' prefix
40 'start': i
41 }
42 elif label.startswith('I-') and current_entity:
43 current_entity['text'] += ' ' + token
44 elif label == 'O':
45 if current_entity:
46 entities.append(current_entity)
47 current_entity = None
48
49if current_entity:
50 entities.append(current_entity)
51
52print("Extracted Entities:")
53for entity in entities:
54 print(f"- {entity['label']}: {entity['text']}")1from transformers import pipeline
2
3# Create NER pipeline
4ner_pipeline = pipeline(
5 "token-classification",
6 model="yashpwr/resume-ner-bert-v2",
7 aggregation_strategy="simple"
8)
9
10# Extract entities
11text = "Sarah Johnson holds a Master's degree in Computer Science from Stanford University. Skills: Python, TensorFlow, SQL."
12results = ner_pipeline(text)
13
14for entity in results:
15 print(f"{entity['entity_group']}: {entity['word']} (confidence: {entity['score']:.3f})")1from transformers import AutoTokenizer, AutoModelForTokenClassification
2import torch
3import numpy as np
4
5# Load model
6model_name = "yashpwr/resume-ner-bert-v2"
7tokenizer = AutoTokenizer.from_pretrained(model_name)
8model = AutoModelForTokenClassification.from_pretrained(model_name)
9
10def extract_entities_with_confidence(text, confidence_threshold=0.5):
11 """Extract entities with confidence scores."""
12 inputs = tokenizer(
13 text,
14 return_tensors="pt",
15 truncation=True,
16 max_length=128,
17 padding=True,
18 return_offsets_mapping=True
19 )
20
21 with torch.no_grad():
22 outputs = model(**inputs)
23 predictions = torch.argmax(outputs.logits, dim=2)
24 probabilities = torch.softmax(outputs.logits, dim=2)
25
26 entities = []
27 current_entity = None
28 offset_mapping = inputs.offset_mapping[0]
29
30 for i, (pred, offset) in enumerate(zip(predictions[0], offset_mapping)):
31 label = model.config.id2label[pred.item()]
32 confidence = probabilities[0][i][pred].item()
33
34 # Skip special tokens
35 if offset[0] == 0 and offset[1] == 0:
36 continue
37
38 if label.startswith('B-'):
39 if current_entity and current_entity['confidence'] >= confidence_threshold:
40 entities.append(current_entity)
41
42 entity_type = label[2:]
43 current_entity = {
44 'text': text[offset[0]:offset[1]],
45 'label': entity_type,
46 'start': offset[0],
47 'end': offset[1],
48 'confidence': confidence
49 }
50
51 elif label.startswith('I-') and current_entity:
52 entity_type = label[2:]
53 if entity_type == current_entity['label']:
54 current_entity['text'] += ' ' + text[offset[0]:offset[1]]
55 current_entity['end'] = offset[1]
56 current_entity['confidence'] = min(current_entity['confidence'], confidence)
57
58 elif label == 'O':
59 if current_entity and current_entity['confidence'] >= confidence_threshold:
60 entities.append(current_entity)
61 current_entity = None
62
63 if current_entity and current_entity['confidence'] >= confidence_threshold:
64 entities.append(current_entity)
65
66 return entities
67
68# Example usage
69text = "Michael Brown is a marketing manager with 10 years of experience at Coca-Cola. Contact: michael.brown@marketing.com"
70entities = extract_entities_with_confidence(text, confidence_threshold=0.3)
71
72for entity in entities:
73 print(f"{entity['label']}: '{entity['text']}' (confidence: {entity['confidence']:.3f})")yashpwr/resume-ner-bertbert-base-cased throughout the pipeline to ensure consistent tokenization between training and inferencereturn_offsets_mapping=True for accurate text reconstructionpip install transformers torch datasets scikit-learn numpy1# Install required packages
2pip install transformers[torch] datasets scikit-learn
3
4# Or using conda
5conda install pytorch transformers -c pytorchyashpwr/resume-ner-bert for the foundation architecture