Skip to main content

Mars Vectorizer

Parses some json/dictionary data object into a grouping and then vectorizes it. Requires that you implement the Vectorizer interface.

Example

Here's a small example of how to use it. First, a parser is defined with class type GroupParser on top. Such a parser takes children of class type PropertyParser, which is the lowest type of parser, or a GroupParser (it is recursively defined). A parser object is returned. It is simply a function taking any dictionary object as its input, and returns a Group object, which's just a mirror of the parser but with names and values set. Then, in this example, the vectorizer will vectorize every parsed object, such that in the end we'll have vectors as values (instead of original floats and strings). Finally, we aggregate all vectors into one object using a weights -dictionary as input, which is a mapping from a group or property name into a float value. That value will be multiplied onto its corresponding vector, if it exists. Otherwise it will be ignored. So in this example, the vector for "b group" will be multiplied with 10.

import numpy as np
from typing import List, Tuple, Union
from mars_vectorizer_sdk import GroupParser, PropertyParser, VectorizedGroupParser, Vectorizer, Dtype

class ExampleVectorizer(Vectorizer):

    def __call__(self, key_value_set: List[Tuple[str, Union[str, float]]]) -> np.ndarray:
        return np.random.uniform(size=(len(key_value_set), 10))

parser = GroupParser(
    name="some object", 
    children=[
        GroupParser(
            name="some group", 
            children=[
                PropertyParser(name="first value", path=["something", "something-under"], dtype=Dtype.STRING),
            ],
        ),
        GroupParser(
            name="another group", 
            children=[
                PropertyParser(name="some value", path=["something", "something-else", "some-value-a"], dtype=Dtype.STRING),
                PropertyParser(name="some other value", path=["something", "something-else", "some-value-b"], dtype=Dtype.FLOAT),
            ],
        )
    ]
)
vec_parser = VectorizedGroupParser.from_group(
    parser,
    vectorizer=ExampleVectorizer(),
)

# Example of usage
json_data = {
    "something": {
        "something-under": "text is here",
        "something-else": {
            "some-value-a": "a value",
            "some-value-b": 10.0,
        },
    }
}
# Parse json data
res = vec_parser(json_data)
print(res) # Full data
print(res.aggregate({"b group": 10}).vector) # aggregated weighted vector

Release files for mars-vectorizer-sdk 0.2.0

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

Source distribution (sdist)

Source distribution for mars-vectorizer-sdk 0.2.0
File Size Uploaded
mars_vectorizer_sdk-0.2.0.tar.gz 3.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for mars-vectorizer-sdk 0.2.0
File Interpreter ABI Platform
mars_vectorizer_sdk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 7.3 kB

Release files / mars_vectorizer_sdk-0.2.0.tar.gz

Download URL mars_vectorizer_sdk-0.2.0.tar.gz
Size 3.4 kB
Tags Source
SHA-256 checksum
How to use checksums
03da912dbf72bed4c409afe67f9b57f1f4a2c5843733174c36fcfa373d56a784
BLAKE2b-256 checksum
How to use checksums
79692314a63bff39c2f0c31a7118caf9d11db73f75042825dc47935527ec4404
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.9.18 Darwin/23.1.0

Release files / mars_vectorizer_sdk-0.2.0-py3-none-any.whl

Download URL mars_vectorizer_sdk-0.2.0-py3-none-any.whl
Size 3.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62b0a2f8df8a4b20e2119f447454a745dc06f4fb1aed005e8e34cd240c946670
BLAKE2b-256 checksum
How to use checksums
24cc908d52b6282719e08ba0349583ab59cb512aa0d009b2ae4197901fb72a22
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.9.18 Darwin/23.1.0

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 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