Skip to main content

Distributional Compositional Python

Project description

"Alice loves Bob" in picture

Distributional Compositional Python

readthedocs Build Status codecov pylint Score PyPI version

discopy is a tool for classical and quantum natural language processing (QNLP) using string diagrams.

from discopy import Ty, Word, Cup, Id

s, n = Ty('s'), Ty('n')
Alice, Bob = Word('Alice', n), Word('Bob', n)
loves = Word('loves', n.r @ s @ n.l)

sentence = Alice @ loves @ Bob >> Cup(n, n.r) @ Id(s) @ Cup(n.l, n)


# 2) Define a model.

from discopy import Model

ob = {s: 1, n: 2}
ar = {Alice: [1, 0], loves: [0, 1, 1, 0], Bob: [0, 1]}
F = Model(ob, ar)


# 3) Compute the meaning!

assert F(sentence)

Requirements

Getting Started

pip install discopy

Documentation

The documentation is hosted at readthedocs.io, you can also checkout the notebooks for a demo!

References

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discopy-0.1.6.tar.gz (27.5 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page