How best to store lexical information at the intermediate stages of a spaCy NLP pipeline

Viewed 155

I have a spaCy-based NLP pipeline that processes large corpora, then searches for matches on specific words (lemma plus part of speech), then records detailed lexical information for every match. What results is a Python dictionary structured as in the following (simplified) snippet, where w is the matched token and sent_id is a unique hash to the sentence/corpus in which the token was found:

this_match = {"tag": w.tag_,
              "dep": w.dep_,
              "parent": w.head_,
              "children": [{"lemma": c.lemma_,
                            "tag": c.tag_}
                            for c in w.children if not c.is_punct]
              "sent_id": sent_id}

These smaller dictionaries, each of which represents the linguistic context in which a word appears, are then added to a top-level dictionary that is keyed to the lemma/POS of each match token w. That dictionary is to serve as a store of lexical information for calculating various statistics on the linguistic characteristics of words.

As you can see, our data structure is a straightforward JSON, with dictionaries and arrays of dictionaries of text. How should I be storing it for follow-on analysis? A purely local solution is all I require at the moment, but if (like Elasticsearch, at 2. below) the solution is clearly scalable, then even better. Here are some of the options I've considered:

  1. Just save them all as JSONs and load them every time you work on the statistics.

  2. Load them into an Elasticsearch index. (The data points are not documents, per se, so Elasticsearch seems like overkill.)

  3. Use some other lighter, simpler database format (TinyDB?).

  4. Pickle to a .pkl archive. (Way too big; not easily transferable to other developers/environments.)

What have you used in the past for storing lexically indexed language data? Is there a go-to utility for this use case? And how do I ensure that my data store is scalable?

This question is more open-ended than I'd normally like to ask or see on Stackoverflow, but I think that it will be useful to enough other developers working in NLP that it's worth asking anyway.

0 Answers
Related