https://github.com/shunk031/allennlp-dataframe-mapper
AllenNLP integration for sklearn-pandas
https://github.com/shunk031/allennlp-dataframe-mapper
allennlp machine-learning pipeline sklearn sklearn-pandas
Last synced: 7 months ago
JSON representation
AllenNLP integration for sklearn-pandas
- Host: GitHub
- URL: https://github.com/shunk031/allennlp-dataframe-mapper
- Owner: shunk031
- License: mit
- Created: 2020-10-20T08:17:52.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2022-09-01T04:38:06.000Z (about 3 years ago)
- Last Synced: 2025-02-17T17:03:52.596Z (8 months ago)
- Topics: allennlp, machine-learning, pipeline, sklearn, sklearn-pandas
- Language: Python
- Homepage:
- Size: 435 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AllenNLP integration for sklearn-pandas



[](https://pypi.python.org/pypi/allennlp-dataframe-mapper)`allennlp-dataframe-mapper` is a Python library that provides [AllenNLP](https://github.com/allenai/allennlp) integration for [sklearn-pandas](https://github.com/scikit-learn-contrib/sklearn-pandas).
## Installation
Installing the library and dependencies is simple using `pip`.
```sh
$ pip install allennlp-dataframe-mapper
```## Example
This library enables users to specify the in a jsonnet config file.
Here is an example of the mapper for a famous [iris dataset](https://archive.ics.uci.edu/ml/datasets/iris).### Config
`allennlp-dataframe-mapper` is specified the transformations of the mapper in `jsonnet` config file like following `mapper_iris.jsonnet`:
```json
{
"type": "default",
"features": [
[["sepal length (cm)"], null],
[["sepal width (cm)"], null],
[["petal length (cm)"], null],
[["petal width (cm)"], null],
[["species"], [{"type": "flatten"}, {"type": "label-encoder"}]],
],
"df_out": true,
}
```### Mapper
The mapper takes a param of transformations from the config file.
We can use the `fit_transform` shortcut to both fit the mapper and see what transformed data.```python
from allennlp.common import Params
from allennlp_dataframe_mapper import DataFrameMapperparams = Params.from_file("mapper_iris.jsonnet")
mapper = DataFrameMapper.from_params(params=params)print(mapper)
# DataFrameMapper(df_out=True,
# features=[(['sepal length (cm)'], None, {}),
# (['sepal width (cm)'], None, {}),
# (['petal length (cm)'], None, {}),
# (['petal width (cm)'], None, {}),
# (['species'], [FlattenTransformer(), LabelEncoder()], {})])mapper.fit_transform(df)
```## License
MIT