Distributional Compositional Python
Project description
Distributional Compositional Python
discopy
computes natural language meaning in pictures.
Recipe
# 1) Draw your picture.
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
- Pregroup grammars and categorical compositional distributional semantics on the nLab
- From Word to Sentence: A Computational Algebraic Approach to Grammar - Lambek (2008)
- A Compositional Distributional Model of Meaning - Clark, Coecke, Sadrzadeh (2008)
- Experimental Support for a Categorical Compositional Distributional Model of Meaning - Grefenstette and Sadrzadeh (2010)
- Functorial Question Answering - De Felice, Meichanetzidis, Toumi (2019)
- The Mathematics of Text Structure - Coecke (2019)
Project details
Release history Release notifications | RSS feed
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.5.tar.gz
(23.9 kB
view hashes)