Reputation: 33
i am trying convert old spacy 2.0 dataset to new spacy 3.0 acceptable format but i am getting this error "char_span() got an unexpected keyword argument 'alignment_mode' " error, How should i resolve this error? i am using this code
import pandas as pd
from tqdm import tqdm
import spacy
from spacy.tokens import DocBin
nlp = spacy.blank("en") # load a new spacy model
db = DocBin() # create a DocBin object
for text, annot in tqdm(TRAIN_DATA): # data in previous format
doc = nlp.make_doc(text) # create doc object from text
ents = []
for start, end, label in annot["entities"]: # add character indexes
span = doc.char_span(start, end, label=label, alignment_mode="contract")
if span is None:
print("Skipping entity")
else:
ents.append(span)
doc.ents = ents # label the text with the ents
db.add(doc)
db.to_disk("./train.spacy") # save the docbin object
after running this script i am getting this error
TypeError: char_span() got an unexpected keyword argument 'alignment_mode'
Upvotes: 1
Views: 579
Reputation: 15593
The alignment_mode
option was added in spaCy v3, but you seem to be using spaCy v2. So if you run the above code with spaCy v3 it should work.
Upvotes: 1