Code Monkey home page Code Monkey logo

mondigy's Introduction

mondigy

Mondigy is a small library for using a Mongodb database as a data loader for Prodigy annotation applications.

Motivation

Prodigy naviely supports loading text data from files and dataset objects, but annotating data that is stored in a MongoDB database is not natively supported.

With mondigy you can annotate data from a MongoDB collection and store your annotations in a MongoDB database.

Features

  • Annotate text data from MongoDB
  • Pipe data directly from your MongoDB database to your Prodigy application

Installation & Setup

Mondigy can be installed via pip install mondigy or by cloning this repo and running python setup.py in the project root.

Mondigy will set up the collections it requires in your mongo database. They are named with a _p.<collection_name>convention. Don't delete these collections or manually edit any of the documents in them.

To set up mondigy, just enter your MongoDB connection info into your prodigy.json config file, which is found in your PRODIGY_HOME directory. The source database and annotations database (where your completed annotations are stored by Prodigy) can be configured independently or the same database can be specified for both if you want everything in the same db. See example_config/prodigy.json for an example config file.

Code Example

Let's define a db connection and start annotating data from our MongoDB database!

Step 1. Add configuration parameters to prodigy.json in your PRODIGY_HOME directory. For this example, we'll be limiting our annotations to the 1000 entries that are in_stock from the products collection of our database. We'll also include the product name and product id in the data returned to Prodigy so we can include that information in a custom view. .

prodigy.json
  ...
  "db": "mondigy.db",
  "db_settings": {
    "mongodb": {
      "source_db": {
        "host": "my.database.com",
        "user": "mongo_user",
        "password": "mongo_pass",
        "database": "my_db",
        "auth_source": "admin",
        "collection": "products",
        "text_field": "description",
        "other_fields": ["product_name", "product_id"],
        "query": {"in_stock": true},
        "limit": 1000
      },
      "annotations_db": {
        "host": "my.database.com",
        "user": "mongo_user",
        "password": "mongo_pass",
        "database": "my_db",
        "auth_source": "admin",
      }
    }
  },
  ...
}

Step 2. Start your Prodigy server and let mondigy point your MongoDB collection at it by supplying the paths of your config file and the Mondigy loader.

prodigy ner.manual my_ner_task en_core_web_sm - --label FEATURE,KEYWORD --loader mondigy.loader

Step 3. Annotate!

License

MIT © John Dagdelen

Aknowledgements

The AnnotationDatabase class is based on code originally written by Haoyan Huo.

mondigy's People

Contributors

jdagdelen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

mangangreg

mondigy's Issues

AttributeError: 'Cursor' object has no attribute 'count'

Hi @jdagdelen Please help me with the issue:

Using 3 label(s): POS, NEU, NEG
Added dataset my_ner_task_mongodb to database Custom MongoDB Database.
Traceback (most recent call last):
File "C:\Users\Surya\anaconda3\lib\runpy.py", line 194, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\Surya\anaconda3\lib\runpy.py", line 87, in run_code
exec(code, run_globals)
File "C:\Users\Surya\anaconda3\lib\site-packages\prodigy_main
.py", line 61, in
controller = recipe(*args, use_plac=True)
File "cython_src\prodigy\core.pyx", line 339, in prodigy.core.recipe.recipe_decorator.recipe_proxy
File "cython_src\prodigy\core.pyx", line 366, in prodigy.core._components_to_ctrl
File "cython_src\prodigy\core.pyx", line 117, in prodigy.core.Controller.init
File "C:\Users\Surya\anaconda3\lib\site-packages\mondigy\database.py", line 161, in count_dataset
return self.link_collection.find({'dataset_id': dataset['_id']}).count()
AttributeError: 'Cursor' object has no attribute 'count'

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.