I have a use case where I want to extract the name from the phonetic transcription.
For example if the phonetic transcription is - “m a j n e j m ɪ z s ʌ m i ɹ z o w ʃ i”, the output should be the name that is - “s ʌ m i ɹ z o w ʃ i” .
Similarly if the phonetic transcription is - “juː kæn kɔːl miː s ʌ m i ɹ z o w ʃ i”, then output would be “s ʌ m i ɹ z o w ʃ i”.
This is nothing but extracting name from the phonetic transcription.
What could be the best suitable and easy way to achieve this?
I think it would be kind of sequence to sequence model where the input is sentence and output is name.
If yes, I am looking for guidance on the model type and if there in any fine tuning that may need to be done for achieving this.
1 Answer
This could be solved with a sequence-to-sequence model, but I feel this might be overkill for your use case.
In your case, it seems that you are trying to label part of the phonetic transcription as a name, which fits more with named-entity recognition.
For NER, I'd recommend using SpaCy for this (https://spacy.io/universe/project/video-spacys-ner-model-alt), but of course, you could implement it in PyTorch or another framework. I also believe you could just use some regex and try to find known names with pattern matching, which is easy to do with SpaCy.
In SpaCy, this could look like this*
- Prepare your dataset
TRAIN_DATA = [
("m a j n e j m ɪ z s ʌ m i ɹ z o w ʃ i", {"entities": [(18, 38, "NAME")]}),
# Add more examples...
]
- Add known cases as rules
import spacy
from spacy.matcher import PhraseMatcher
import re
# Initialize spaCy
nlp = spacy.blank("en")
# List of known names (for demonstration)
known_names = ["Alice", "Bob", "Charlie"]
# Convert the list of names into spaCy Doc objects
patterns = [nlp.make_doc(name) for name in known_names]
# Initialize the PhraseMatcher
matcher = PhraseMatcher(nlp.vocab, attr="ORTH")
# Add the patterns to the matcher
matcher.add("KNOWN_NAMES", patterns)
# Test text
text = "Alice and Bob are friends, but Charlie is not."
# Process the text with spaCy
doc = nlp(text)
# Use the matcher on the doc
matches = matcher(doc)
# Iterate over the matches
for match_id, start, end in matches:
span = doc[start:end] # The matched span
print(span.text)
- Train a model
import spacy
from spacy.training import Example
# Load a pre-existing spaCy model or create a blank one
nlp = spacy.blank("en") # For example, start with a blank English model
# Add the NER pipeline component
if "ner" not in nlp.pipe_names:
ner = nlp.create_pipe("ner")
nlp.add_pipe("ner", last=True)
else:
ner = nlp.get_pipe("ner")
# Add the new label to ner
ner.add_label("NAME")
# Start the training
nlp.begin_training()
# Training loop
for itn in range(10): # Number of iterations
random.shuffle(TRAIN_DATA)
losses = {}
for text, annotations in TRAIN_DATA:
doc = nlp.make_doc(text)
example = Example.from_dict(doc, annotations)
nlp.update([example], drop=0.5, losses=losses)
print(losses)
- Use your model
doc = nlp("n y uː ɛ k s æ m p ə l")
for ent in doc.ents:
print(ent.text, ent.label_)
*this is untested code, but it should be close enough to something that would work
-
$\begingroup$ Thanks @Valentin. I tried above code , but when I use the model for going through the doc entries and print the text and label, its not printing anything. I have used the same code as above except not the part of "Add known cases as rules" and the input to nlp for testing the model is "m a j n e j m ɪ z b ʌ s o w ɹ ɑ d͡ʒ ɡ ʊ l i" Is it because of this line
nlp = spacy.blank("en")
? Can NLP be applied to IPA transcribed sequences? $\endgroup$ Commented Apr 14 at 4:08