rankflow


Namerankflow JSON
Version 0.1.4 PyPI version JSON
download
home_pageNone
SummaryPlot how multiple ranks evolved over processing steps - draw a rankflow.
upload_time2024-07-14 20:43:25
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords rankflow rank flow plot rag retriever evaluation rag-evaluation rag-eval rag-eval-plot rag-evaluation-plot
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # RankFlow

![pypi version badge](https://img.shields.io/pypi/v/rankflow.svg)
![python version badge](https://img.shields.io/pypi/pyversions/rankflow.svg)
![license badge](https://img.shields.io/pypi/l/rankflow.svg)
![monthly downloads badge](https://img.shields.io/pypi/dm/rankflow.svg)

Library for plotting multiple ranks evolved over processing steps - drawing a rankflow.

![RankFlow](https://raw.githubusercontent.com/izikeros/rankflow/main/img/rankflow_crop.png)

RankFlow is a Python package that allows you to create rank flow plots (bump charts), helping visualize the changes in ranking of nodes.

Initially it was applied to re-ranking visualization of nodes (parts of documents, document chunks) during the retrieval and re-ranking processes within a Retrieval Augmented Generation (RAG) retriever, but the usage is not limited to RAG.

⭐️ Please star the repository if you find it useful.

## Installation

```bash
pip install rankflow
```

## Usage

### plot from pandas DataFrame

Start with creating [pandas](https://pandas.pydata.org/) DataFrame with ranks for each document at each step.

```python
import pandas as pd
import matplotlib.pyplot as plt
from rankflow import RankFlow

data = {"Doc 1": [2, 1, 3, 2], "Doc 2": [1, 2, 1, 3], "Doc 3": [3, 3, 2, 1]}
df = pd.DataFrame(data, index=["Step_1", "Step_2", "Step_3", "Step_4"])
```
This creates the following DataFrame:

![](https://raw.githubusercontent.com/izikeros/rankflow/main/img/dataframe.png)

**NOTE:** The rows of the DataFrame are the steps and the columns are the documents. The values are the ranks of the documents at each step. Remember to define proper column names and index values since they will be used as labels in the plot.

When the DataFrame is ready, then it is time to create RankFlow object and call `plot()` method.

```python
rf = RankFlow(df=df)
rf.plot()

# save the plot to png
plt.savefig("rankflow.png")

plt.show()
```
Here is the expected output:

![](https://raw.githubusercontent.com/izikeros/rankflow/main/img/rankflow_basic_pandas.png)

### plot from numpy array
You can also create RankFlow object without using pandas DataFrame. You can pass numpy array with ranks for each document at each step and provide labels for steps and documents.
```python
import matplotlib.pyplot as plt
from rankflow import RankFlow
import numpy as np

my_step_labels: list[str] = [
    "Hybrid Search",
    "Cross-encoder",
    "Graph-reranker",
    "Booster",
]
my_chunk_labels: list[str] = [
    "Doc 0",
    "Doc 1",
    "Doc 2",
    "Doc 3",
    "Doc 4",
    "Doc 5",
    "Doc 6",
    "Doc 7",
    "Doc 8",
    "Doc 9",
]
my_ranks = np.array(
    [
        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],
        [3, 0, 2, 4, 1, 6, 7, 9, 5, 8],
        [2, 3, 0, 4, 6, 1, 7, 8, 5, 9],
        [5, 3, 2, 1, 0, 4, 6, 7, 8, 9],
    ]
)

rf = RankFlow(
    ranks=my_ranks,
    step_labels=my_step_labels,
    chunk_labels=my_chunk_labels,
    fig_size=(6, 6),
    title_font_size=24,
)
_ = rf.plot()
plt.show()
```

This should produce the following plot:

![RankFlow](https://raw.githubusercontent.com/izikeros/rankflow/main/img/rankflow.png)

## Further reading

There is and blog article describing usage of this package in RAG retriever: [RankFlow plot for retriever visual evaluation](https://safjan.com/rankflow-plot-for-retriever-visual-evaluation/) that might be helpful if you are wondering how to efficienty track rank changes in your retriever and finally visualize them.

## License

[MIT](LICENSE) © [Krystian Safjan](https://safjan.com/).

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "rankflow",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "rankflow, rank, flow, plot, RAG, retriever, evaluation, rag-evaluation, rag-eval, rag-eval-plot, rag-evaluation-plot",
    "author": null,
    "author_email": "Krystian Safjan <ksafjan@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a2/c8/1c8a76969dee9224cfa5bc28c41f6b66b52bff8b6aadd95df35676ad98e7/rankflow-0.1.4.tar.gz",
    "platform": null,
    "description": "# RankFlow\n\n![pypi version badge](https://img.shields.io/pypi/v/rankflow.svg)\n![python version badge](https://img.shields.io/pypi/pyversions/rankflow.svg)\n![license badge](https://img.shields.io/pypi/l/rankflow.svg)\n![monthly downloads badge](https://img.shields.io/pypi/dm/rankflow.svg)\n\nLibrary for plotting multiple ranks evolved over processing steps - drawing a rankflow.\n\n![RankFlow](https://raw.githubusercontent.com/izikeros/rankflow/main/img/rankflow_crop.png)\n\nRankFlow is a Python package that allows you to create rank flow plots (bump charts), helping visualize the changes in ranking of nodes.\n\nInitially it was applied to re-ranking visualization of nodes (parts of documents, document chunks) during the retrieval and re-ranking processes within a Retrieval Augmented Generation (RAG) retriever, but the usage is not limited to RAG.\n\n\u2b50\ufe0f Please star the repository if you find it useful.\n\n## Installation\n\n```bash\npip install rankflow\n```\n\n## Usage\n\n### plot from pandas DataFrame\n\nStart with creating [pandas](https://pandas.pydata.org/) DataFrame with ranks for each document at each step.\n\n```python\nimport pandas as pd\nimport matplotlib.pyplot as plt\nfrom rankflow import RankFlow\n\ndata = {\"Doc 1\": [2, 1, 3, 2], \"Doc 2\": [1, 2, 1, 3], \"Doc 3\": [3, 3, 2, 1]}\ndf = pd.DataFrame(data, index=[\"Step_1\", \"Step_2\", \"Step_3\", \"Step_4\"])\n```\nThis creates the following DataFrame:\n\n![](https://raw.githubusercontent.com/izikeros/rankflow/main/img/dataframe.png)\n\n**NOTE:** The rows of the DataFrame are the steps and the columns are the documents. The values are the ranks of the documents at each step. Remember to define proper column names and index values since they will be used as labels in the plot.\n\nWhen the DataFrame is ready, then it is time to create RankFlow object and call `plot()` method.\n\n```python\nrf = RankFlow(df=df)\nrf.plot()\n\n# save the plot to png\nplt.savefig(\"rankflow.png\")\n\nplt.show()\n```\nHere is the expected output:\n\n![](https://raw.githubusercontent.com/izikeros/rankflow/main/img/rankflow_basic_pandas.png)\n\n### plot from numpy array\nYou can also create RankFlow object without using pandas DataFrame. You can pass numpy array with ranks for each document at each step and provide labels for steps and documents.\n```python\nimport matplotlib.pyplot as plt\nfrom rankflow import RankFlow\nimport numpy as np\n\nmy_step_labels: list[str] = [\n    \"Hybrid Search\",\n    \"Cross-encoder\",\n    \"Graph-reranker\",\n    \"Booster\",\n]\nmy_chunk_labels: list[str] = [\n    \"Doc 0\",\n    \"Doc 1\",\n    \"Doc 2\",\n    \"Doc 3\",\n    \"Doc 4\",\n    \"Doc 5\",\n    \"Doc 6\",\n    \"Doc 7\",\n    \"Doc 8\",\n    \"Doc 9\",\n]\nmy_ranks = np.array(\n    [\n        [0, 1, 2, 3, 4, 5, 6, 7, 8, 9],\n        [3, 0, 2, 4, 1, 6, 7, 9, 5, 8],\n        [2, 3, 0, 4, 6, 1, 7, 8, 5, 9],\n        [5, 3, 2, 1, 0, 4, 6, 7, 8, 9],\n    ]\n)\n\nrf = RankFlow(\n    ranks=my_ranks,\n    step_labels=my_step_labels,\n    chunk_labels=my_chunk_labels,\n    fig_size=(6, 6),\n    title_font_size=24,\n)\n_ = rf.plot()\nplt.show()\n```\n\nThis should produce the following plot:\n\n![RankFlow](https://raw.githubusercontent.com/izikeros/rankflow/main/img/rankflow.png)\n\n## Further reading\n\nThere is and blog article describing usage of this package in RAG retriever: [RankFlow plot for retriever visual evaluation](https://safjan.com/rankflow-plot-for-retriever-visual-evaluation/) that might be helpful if you are wondering how to efficienty track rank changes in your retriever and finally visualize them.\n\n## License\n\n[MIT](LICENSE) \u00a9 [Krystian Safjan](https://safjan.com/).\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Plot how multiple ranks evolved over processing steps - draw a rankflow.",
    "version": "0.1.4",
    "project_urls": {
        "Bug tracker": "https://github.com/izikeros/rankflow/issues",
        "Source": "https://github.com/izikeros/rankflow"
    },
    "split_keywords": [
        "rankflow",
        " rank",
        " flow",
        " plot",
        " rag",
        " retriever",
        " evaluation",
        " rag-evaluation",
        " rag-eval",
        " rag-eval-plot",
        " rag-evaluation-plot"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9e967c21d9232e220cad555c57034aab0ccf67a3dd704d1a5399907572e60f18",
                "md5": "11a7c8facd4d5dce30c39a0216089047",
                "sha256": "c7935542c55fd394c50f379e716ce5ae579ddecad76b7f08f9fed59742220e47"
            },
            "downloads": -1,
            "filename": "rankflow-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "11a7c8facd4d5dce30c39a0216089047",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 6324,
            "upload_time": "2024-07-14T20:43:23",
            "upload_time_iso_8601": "2024-07-14T20:43:23.632432Z",
            "url": "https://files.pythonhosted.org/packages/9e/96/7c21d9232e220cad555c57034aab0ccf67a3dd704d1a5399907572e60f18/rankflow-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a2c81c8a76969dee9224cfa5bc28c41f6b66b52bff8b6aadd95df35676ad98e7",
                "md5": "b77c274c5b86031623599be6350215bf",
                "sha256": "077dfd879be8feebb686a5f12908092dbfd0d3a5989cc7e9da0bdb815e88ae8a"
            },
            "downloads": -1,
            "filename": "rankflow-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "b77c274c5b86031623599be6350215bf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 242903,
            "upload_time": "2024-07-14T20:43:25",
            "upload_time_iso_8601": "2024-07-14T20:43:25.213150Z",
            "url": "https://files.pythonhosted.org/packages/a2/c8/1c8a76969dee9224cfa5bc28c41f6b66b52bff8b6aadd95df35676ad98e7/rankflow-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-14 20:43:25",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "izikeros",
    "github_project": "rankflow",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rankflow"
}
        
Elapsed time: 0.30164s