Skip to main content

pyClickModels Build Status Coverage Status PyPI version Pyversions GitHub license

A Cython implementation of ClickModels that uses Probabilistic Graphical Models to infer user behavior when interacting with Search Page Results (Ranking).

How It Works

ClickModels uses the concept of Probabilistic Graphical Models to model components that describe the interactions between users and a list of items ranked by a set of retrieval rules.

These models tend to be useful when it's desired to understand whether a given document is a good match for a given search query or not which is also known in literature as Judgments grades. This is possible through evaluating past observed clicks and the positions at which the document appeared on the results pages for each query.

There are several proposed approaches to handle this problem. This repository implements a Dynamic Bayesian Network, similar to previous works also done in Python:

dbn

Main differences are:

  1. Implemented on top of Cython: solutions already public available rely on CPython integrated with PyPy for additional speed ups. Unfortunatelly this still might not be good enough in terms of performance. To work on that, this implementation relies 100% on C/C++ for further optimization in speed. Despite not having an official benchmark, it's expected an improvement of 15x ~ 18x on top of CPython (same data lead to an increase of ~3x when using PyPy).
  2. Memory Friendly: expects input data to follow a JSON format with all sessions of clickstream already expressed for each row. This saves memory and allows for the library to process bigger amounts of data.
  3. Purchase variable: as businesses such as eCommerces can greately benefit from better understanding their search engine, this repository added the variable Purchase to further describe customers behaviors.

The file notebooks/DBN.ipynb has a complete description of how the model has been implemented along with all the mathematics involved.

Instalation

As this project relies on binaries compiled by Cython, currently only Linux (manylinux) platform is supported. It can be installed with:

pip install pyClickModels

Getting Started

Input Data

pyClickModels expects input data to be stored in a set of compressed gz files located on the same folder. They all should start with the string "judgments", for instance, judgments0.gz. Each file should contain line separated JSONs. The following is an example of each JSON line:

{
    "search_keys": {
        "search_term": "blue shoes",
        "region": "south",
	"favorite_brand": "super brand",
	"user_size": "L",
	"avg_ticket": 10
    },
    "judgment_keys": [
        {
	    "session": [
                {"click": 0, "purchase": 0, "doc": "doc0"}
                {"click": 1, "purchase": 0, "doc": "doc1"}
                {"click": 1, "purchase": 1, "doc": "doc2"}
	    ]
        },
        {
	    "session": [
                {"click": 1, "purchase": 0, "doc": "doc0"}
                {"click": 0, "purchase": 0, "doc": "doc1"}
                {"click": 0, "purchase": 0, "doc": "doc2"}
	    ]
        }
    ]
}

The key search_keys sets the context for the search. In the above example, a given customer (or cluster of customers with the same context) searched for blue shoes. Their region is south (it could be any chosen value), favorite brand is super brand and so on.

These keys sets the context for which the search happened. When pyClickModels runs its optimization, it will consider all the context at once. This means that the Judgments obtained are also on the whole context setting.

If no context is desired, just use {"search_keys": {"search_term": "user search"}}.

There's no required schema here which means the library loops through all keys available in search_keys and builds the optimization process considering the whole context as a single query.

As for the judgment_keys, this is a list of sessions. The key session is mandatory. Each session contains the clickstream of users (if the variable purchase is not required set it to 0).

For running DBN from pyClickModels, here's a simple example:

from pyClickModels.DBN import DBN

model = DBN()
model.fit(input_folder="/tmp/clicks_data/", iters=10)
model.export_judgments("/tmp/output.gz")

Output file will contain a NEWLINE JSON separated file with the judgments for each query and each document observed for that query, i.e.:

{"search_term:blue shoes|region:south|brand:super brand": {"doc0": 0.2, "doc1": 0.3, "doc2": 0.4}}
{"search_term:query|region:north|brand:other_brand": {"doc0": 0.0, "doc1": 0.0, "doc2": 0.1}}

Judgments here varies between 0 and 1. Some libraries requires it to range between integers 0 and 4. Choose a proper transformation in this case that better suits your data.

Warnings

This library is still alpha! Use it with caution. It's been fully unittested but still parts of it uses pure C whose exceptions might not have been fully considered yet. It's recommended to, before using this library in production evironments, to fully test it with different datasets and sizes to evaluate how it performs.

Contributing

Contributions are very welcome! Also, if you find bugs, please report them :).

Metadata

Release files for pyClickModels 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyClickModels 0.0.2
File Size Uploaded
pyClickModels-0.0.2.tar.gz 167.5 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for pyClickModels 0.0.2
File
pyClickModels-0.0.2-cp38-cp38-manylinux2010_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.12+ x86-64 Details
pyClickModels-0.0.2-cp38-cp38-manylinux1_x86_64.whl CPython 3.8 CPython 3.8 Linux glibc 2.5+ x86-64 Details
pyClickModels-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 Details
pyClickModels-0.0.2-cp37-cp37m-manylinux1_x86_64.whl CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64 Details
pyClickModels-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 Details
pyClickModels-0.0.2-cp36-cp36m-manylinux1_x86_64.whl CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64 Details
pyClickModels-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.12+ x86-64 Details
pyClickModels-0.0.2-cp35-cp35m-manylinux1_x86_64.whl CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64 Details

Total release size: 7.1 MB

Release files / pyClickModels-0.0.2.tar.gz

Download URL pyClickModels-0.0.2.tar.gz
Size 167.5 kB
Tags Source
SHA-256 checksum
How to use checksums
3ac63b80498c74cec1af488a9a934c085be10dce093d380703eea9cf4a0a8ca1
BLAKE2b-256 checksum
How to use checksums
3f5f5229d10f6eec879ad957594e179cc1e320353e4870f77e20987e2cc34117
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp38-cp38-manylinux2010_x86_64.whl

Download URL pyClickModels-0.0.2-cp38-cp38-manylinux2010_x86_64.whl
Size 891.2 kB
Tags CPython 3.8 Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
74f76e6378982adafa90a23850d7bb413f7f36da54afbbd8852b5c9c5c5ae0f2
BLAKE2b-256 checksum
How to use checksums
6a70d5c7600e282c8e264d53a1c32899d53d88a7806263027e40c19a298a7e2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp38-cp38-manylinux1_x86_64.whl

Download URL pyClickModels-0.0.2-cp38-cp38-manylinux1_x86_64.whl
Size 891.2 kB
Tags CPython 3.8 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
e4f352d669f3ee0f07190ed9330abb33fe50a53cbf77ef48e925cf0fe4b9c958
BLAKE2b-256 checksum
How to use checksums
352929768793bed380059a55f6b7105a4050eba753d8ad2be5667f500cd0a9d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl

Download URL pyClickModels-0.0.2-cp37-cp37m-manylinux2010_x86_64.whl
Size 862.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
dd900c8fbb5e2e9ab7f64c97b3309e6b5cb85cf37fdcd7be977b54d80ca0d003
BLAKE2b-256 checksum
How to use checksums
f46ce5b2f32169200c1af203f56e81fad19bf00d2eda8bf6cbf23e5cb4b11f8f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp37-cp37m-manylinux1_x86_64.whl

Download URL pyClickModels-0.0.2-cp37-cp37m-manylinux1_x86_64.whl
Size 862.4 kB
Tags CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
409e85c81002904d3c7a071f0e8734bbec25cef679cd31c35b7f138ad8b1fbc3
BLAKE2b-256 checksum
How to use checksums
31594017260702fa5762973b8cc0ca5cb03aed478afec2df9ca01bcac16f2fc5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl

Download URL pyClickModels-0.0.2-cp36-cp36m-manylinux2010_x86_64.whl
Size 868.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
14faa053d1352068f1178527402447f7c73408317297339bb1ae956efd4b97da
BLAKE2b-256 checksum
How to use checksums
545e4a1d01bad49906c919c7431a3c86de64e06076210ed66c3c7bd473d1726b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp36-cp36m-manylinux1_x86_64.whl

Download URL pyClickModels-0.0.2-cp36-cp36m-manylinux1_x86_64.whl
Size 868.2 kB
Tags CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
88cae68558c39f56edddbffc1a0e7039ad767ac74e316c064a21f9d47851001a
BLAKE2b-256 checksum
How to use checksums
ce88f48062d41a149a66d01c30f11208e2f2f70c574a3eadc169b5ee8cef64b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl

Download URL pyClickModels-0.0.2-cp35-cp35m-manylinux2010_x86_64.whl
Size 842.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.12+ x86-64
SHA-256 checksum
How to use checksums
12550f3cdde87d5fc42e25f6a69e32e35a647071ad71751c4758bb06730261d5
BLAKE2b-256 checksum
How to use checksums
daeca27fc371d0316f71a18dc3defb2fa71c5d2adf516b7cb776ca1d0610e574
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release files / pyClickModels-0.0.2-cp35-cp35m-manylinux1_x86_64.whl

Download URL pyClickModels-0.0.2-cp35-cp35m-manylinux1_x86_64.whl
Size 842.7 kB
Tags CPython 3.5 CPython 3.5 pymalloc Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
9e4f93fee202692c1d7d052ec88fd72224f869f286e6bdf9b5bc6165dfcec087
BLAKE2b-256 checksum
How to use checksums
fa64abfa1860936778610de3e02fee278ba4fcef63c90471298d2f3efa25ae6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.6.9

Release history Release notifications | RSS feed

This release

0.0.2 This release

9 release files

0.0.1

9 release files

0.0.0

9 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page