# -*- coding: utf-8 -*-
from setuptools import setup

packages = \
['collatable', 'collatable.extras', 'collatable.fields']

package_data = \
{'': ['*']}

install_requires = \
['numpy>=1.0.0,<2.0.0']

setup_kwargs = {
    'name': 'collatable',
    'version': '0.1.1',
    'description': 'Constructing batched tensors for any machine learning tasks',
    'long_description': '# Collatable\n\n[![Actions Status](https://github.com/altescy/collatable/workflows/CI/badge.svg)](https://github.com/altescy/collatable/actions/workflows/ci.yml)\n[![License](https://img.shields.io/github/license/altescy/collatable)](https://github.com/altescy/collatable/blob/main/LICENSE)\n[![Python version](https://img.shields.io/pypi/pyversions/collatable)](https://github.com/altescy/collatable)\n[![pypi version](https://img.shields.io/pypi/v/collatable)](https://pypi.org/project/collatable/)\n\nConstructing batched tensors for any machine learning tasks\n\n## Installation\n\n```bash\npip install collatable\n```\n\n## Examples\n\nThe following scripts show how to tokenize/index/collate your dataset with `collatable`:\n\n### Text Classification\n\n```python\nimport collatable\nfrom collatable import Instance, LabelField, MetadataField, TextField\nfrom collatable.extras.indexer import LabelIndexer, TokenIndexer\n\ndataset = [\n    ("this is awesome", "positive"),\n    ("this is a bad movie", "negative"),\n    ("this movie is an awesome movie", "positive"),\n    ("this movie is too bad to watch", "negative"),\n]\n\n# Set up indexers for tokens and labels\nPAD_TOKEN = "<PAD>"\nUNK_TOKEN = "<UNK>"\ntoken_indexer = TokenIndexer[str](specials=[PAD_TOKEN, UNK_TOKEN], default=UNK_TOKEN)\nlabel_indexer = LabelIndexer[str]()\n\n# Load training dataset\ninstances = []\nwith token_indexer.context(train=True), label_indexer.context(train=True):\n    for id_, (text, label) in dataset:\n        # Prepare each field with the corresponding field class\n        text_field = TextField(\n            text.split(),\n            indexer=token_indexer,\n            padding_value=token_indexer[PAD_TOKEN],\n        )\n        label_field = LabelField(\n            label,\n            indexer=label_indexer,\n        )\n        metadata_field = Metadata({"id": id_})\n        # Combine these fields into instance\n        instance = Instance(\n            text=text_field,\n            label=label_field,\n            metadata=metadata_field,\n        )\n        instances.append(instance)\n\n# Collate instances and build batch\noutput = collatable.collate(instances)\nprint(output)\n```\n\nExecution result:\n\n```text\n{\'label\': array([0, 1, 0, 1], dtype=int32),\n \'metadata\': [{\'id\': 0}, {\'id\': 1}, {\'id\': 2}, {\'id\': 3}],\n \'text\': {\n    \'token_ids\': array([[ 3,  4,  5,  0,  0,  0,  0],\n                        [ 3,  4,  6,  7,  8,  0,  0],\n                        [ 3,  8,  4,  9,  5,  8,  0],\n                        [ 3,  8,  4, 10,  7, 11, 12]]),\n    \'lengths\': array([3, 5, 6, 7])}}\n```\n\n### Sequence Labeling\n\n```python\nimport collatable\nfrom collatable import Instance, SequenceLabelField, TextField\nfrom collatable.extras.indexer import LabelIndexer, TokenIndexer\n\ndataset = [\n    (["my", "name", "is", "john", "smith"], ["O", "O", "O", "B", "I"]),\n    (["i", "lived", "in", "japan", "three", "years", "ago"], ["O", "O", "O", "U", "O", "O", "O"]),\n]\n\n# Set up indexers for tokens and labels\nPAD_TOKEN = "<PAD>"\ntoken_indexer = TokenIndexer[str](specials=(PAD_TOKEN,))\nlabel_indexer = LabelIndexer[str]()\n\n# Load training dataset\ninstances = []\nwith token_indexer.context(train=True), label_indexer.context(train=True):\n    for tokens, labels in dataset:\n        text_field = TextField(tokens, indexer=token_indexer, padding_value=token_indexer[PAD_TOKEN])\n        label_field = SequenceLabelField(labels, text_field, indexer=label_indexer)\n        instance = Instance(text=text_field, label=label_field)\n        instances.append(instance)\n\noutput = collatable.collate(instances)\nprint(output)\n```\n\nExecution result:\n\n```text\n{\'text\': {\n    \'token_ids\': array([[ 1,  2,  3,  4,  5,  0,  0],\n                        [ 6,  7,  8,  9, 10, 11, 12]]),\n    \'lengths\': array([5, 7])},\n \'label\': array([[0, 0, 0, 1, 2, 0, 0],\n                 [0, 0, 0, 3, 0, 0, 0]])}\n```\n\n### Relation Extraction\n\n```python\nfrom collatable.extras.indexer import LabelIndexer, TokenIndexer\nfrom collatable.fields.adjacency_field import AdjacencyField\nfrom collatable.fields.list_field import ListField\nfrom collatable.fields.span_field import SpanField\nfrom collatable.fields.text_field import TextField\nfrom collatable.instance import Instance\n\nPAD_TOKEN = "<PAD>"\ntoken_indexer = TokenIndexer[str](specials=(PAD_TOKEN,))\nlabel_indexer = LabelIndexer[str]()\n\ninstances = []\nwith token_indexer.context(train=True), label_indexer.context(train=True):\n    text = TextField(\n        ["john", "smith", "was", "born", "in", "new", "york", "and", "now", "lives", "in", "tokyo"],\n        indexer=token_indexer,\n        padding_value=token_indexer[PAD_TOKEN],\n    )\n    spans = ListField([SpanField(0, 2, text), SpanField(5, 7, text), SpanField(11, 12, text)])\n    relations = AdjacencyField([(0, 1), (0, 2)], spans, labels=["born-in", "lives-in"], indexer=label_indexer)\n    instance = Instance(text=text, spans=spans, relations=relations)\n    instances.append(instance)\n\n    text = TextField(\n        ["tokyo", "is", "the", "capital", "of", "japan"],\n        indexer=token_indexer,\n        padding_value=token_indexer[PAD_TOKEN],\n    )\n    spans = ListField([SpanField(0, 1, text), SpanField(5, 6, text)])\n    relations = AdjacencyField([(0, 1)], spans, labels=["capital-of"], indexer=label_indexer)\n    instance = Instance(text=text, spans=spans, relations=relations)\n    instances.append(instance)\n\noutput = Instance.collate(instances)\nprint(output)\n```\n\nExecution result:\n\n```text\n{\'text\': {\n    \'token_ids\': array([[ 1,  2,  3,  4,  5,  6,  7,  8,  9, 10,  5, 11],\n                        [11, 12, 13, 14, 15, 16,  0,  0,  0,  0,  0,  0]]),\n    \'lengths\': array([12,  6])},\n \'spans\': array([[[ 0,  2],\n                  [ 5,  7],\n                  [11, 12]],\n                 [[ 0,  1],\n                  [ 5,  6],\n                  [-1, -1]]]),\n \'relations\': array([[[-1,  0,  1],\n                      [-1, -1, -1],\n                      [-1, -1, -1]],\n\n                     [[-1,  2, -1],\n                      [-1, -1, -1],\n                      [-1, -1, -1]]], dtype=int32)}\n```\n',
    'author': 'altescy',
    'author_email': 'altescy@fastmail.com',
    'maintainer': 'None',
    'maintainer_email': 'None',
    'url': 'https://github.com/altescy/collatable',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.8.1,<4.0',
}


setup(**setup_kwargs)
