# Tensor


```python
from lambeq import ccg2discocat

depccg_parser = ccg2discocat.DepCCGParser()
diagram = depccg_parser.sentence2diagram('Alice gives Claire the flowers')
diagram.draw()
```


```python
from lambeq.tensor import TensorAnsatz, MPSAnsatz, SpiderAnsatz
from lambeq.core.types import AtomicType
from discopy import Dim

N = AtomicType.NOUN
S = AtomicType.SENTENCE
```


```python
TensorAnsatz({N: Dim(4), S: Dim(3)})(diagram).draw()
```


```python
MPSAnsatz({N: Dim(4), S: Dim(3)}, bond_dim=5)(diagram).draw(figsize=(8, 4))
```


```python
SpiderAnsatz({N: Dim(4), S: Dim(3)})(diagram).draw()
```


```python
import torch as th
from sympy import default_sort_key

d = SpiderAnsatz({N: Dim(4), S: Dim(3)}, max_order=2)(diagram)

syms = sorted(d.free_symbols, key=default_sort_key)
sym_dict = {k: th.ones(k.size) for k in syms}
subbed_diagram = d.lambdify(*syms)(*sym_dict.values())
```


```python
import tensornetwork as tn
subbed_diagram.eval(contractor=tn.contractors.auto)
```




    Tensor(dom=Dim(1), cod=Dim(3), array=[256., 256., 256.])



4647eec588c5456eb593f73a2975a4453f84494a
ipynb
Jupyter Notebook
docs/examples/tensor.ipynb
kinianlo/lambeq
86aedb24bf826c226f2845af4327cf616cd01a1e
Apache-2.0
2021-11-24T10:26:36.000Z
2021-11-24T10:26:36.000Z
docs/examples/tensor.ipynb
yliu9418/lambeq
357fb893e01e2b41d7628ceaed265356702ca5fa
Apache-2.0
docs/examples/tensor.ipynb
yliu9418/lambeq
357fb893e01e2b41d7628ceaed265356702ca5fa
Apache-2.0
Qwen/Qwen-72B
1. YES
2. YES