No project description provided
Project description
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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file mars_vectorizer_sdk-0.2.0.tar.gz
.
File metadata
- Download URL: mars_vectorizer_sdk-0.2.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.9.18 Darwin/23.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 03da912dbf72bed4c409afe67f9b57f1f4a2c5843733174c36fcfa373d56a784 |
|
MD5 | cec27fa288816762f068518486014263 |
|
BLAKE2b-256 | 79692314a63bff39c2f0c31a7118caf9d11db73f75042825dc47935527ec4404 |
File details
Details for the file mars_vectorizer_sdk-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: mars_vectorizer_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 3.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.9.18 Darwin/23.1.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 62b0a2f8df8a4b20e2119f447454a745dc06f4fb1aed005e8e34cd240c946670 |
|
MD5 | a601c21c9ab05d8ced3be35b11c50638 |
|
BLAKE2b-256 | 24cc908d52b6282719e08ba0349583ab59cb512aa0d009b2ae4197901fb72a22 |