I am trying to parse addresses from various documents using spaCy using NER but the results are not so accurate.

I know this is bit generic question but it would be a great help if I could get reference of any past work or good articles or techniques to apply to this.

  • $\begingroup$ Can you provide some of the following: 1) which language is your text in? 2) some examples of sentences containing addresses you'd want to pick up 3) perhaps examples of mistakes 4) Are you training your own model or are you using a model as is? $\endgroup$ May 8, 2020 at 7:21
  • $\begingroup$ 1) which language is your text in? - English 2) some examples of sentences containing addresses you'd want to pick up - Data are contarct documents, it contains addresses in different formates(of different countries),some are comma saperated, some are new line saperated etc 3) perhaps examples of mistakes - currently en model of SpaCy is even not able to tag entities clearly 4) Are you training your own model or are you using a model as is? - tried as it is but very poor in results to need to know a generic approach to train own model. any referance code will be helpfu; $\endgroup$
    – SKB
    May 9, 2020 at 8:03
  • $\begingroup$ Can you please edit your question to add what you wrote in your last comment (that was what I was trying to do by asking all of them). And please do add actual examples and not just "addresses are in different formats", that doesn't really help us understand what you are facing. I have added a link on how to train a SpaCy NER model in my answer. It's very well documented on their website $\endgroup$ May 9, 2020 at 11:03

1 Answer 1


Please look at my comment to add more information to your post. Based on the information you provided, here are my remarks:

  • SpaCy is trained to find locations, not addresses per se

If you use a "common" language, SpaCy is trained using WikiNER data, where locations aren't addresses but more like geographical places like city names, country names etc. So it's quite normal to not be able to detect full addresses.

You likely need to train your own entity recognizer. They detail how to do this on their website, including code samples: https://spacy.io/usage/training#ner

  • Don't underestimate SpaCy's rule-based matching

Is it a fancy neural network? No. Does it matter? Also no. SpaCy allows you to create rules to find entities and in cases like addresses which are generally following a pattern across entities.

  • $\begingroup$ spacy.io/usage/training#ner this link suggests how to train the model, but when I did it. It was location specific. Like in few documents address was at the beginning, so model started Considering anything at start of document is address. My question is how to train the model for different locations of addresses (and some time different formats). $\endgroup$
    – SKB
    May 10, 2020 at 3:06
  • $\begingroup$ Well that is a learning artifact, something you need to figure out how to mitigate. There is nothing in the model that explicitly uses location. One way to mitigate could be to train on lines/sentences of your contract as opposed to the whole document at once. That way, you remove the "location" information. $\endgroup$ May 10, 2020 at 13:40
  • $\begingroup$ Thanks "location specific" I meant position specific in above comment. Are you suggesting to just somehow crop the area where address is located in documents and then train on it or something else. $\endgroup$
    – SKB
    May 10, 2020 at 16:53
  • 2
    $\begingroup$ What I mean is that an NER model is using both "what" the tokens are and "where" they are to make a prediction. If you see that the model favours tokens that are at the beginning of the document, you could split the document into sentences, so that this effect is less pronounced. So instead of having one document with 10 sentences, you would create 1 document with 10 each of the sentences $\endgroup$ May 10, 2020 at 20:51
  • $\begingroup$ Makes sense.. Thanks. $\endgroup$
    – SKB
    May 11, 2020 at 1:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.