<jupyter_start><jupyter_text>Metadata Schema and Validation<jupyter_code>from seldon_core.metadata import validate_model_metadata
import yaml<jupyter_output><empty_output><jupyter_text>Examples DescriptionSimple and transparent list of valid model metadata definitions  kfserving Schema<jupyter_code>data = """
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon
inputs:
- datatype: BYTES
  name: input
  shape: [ 1, 4 ]
outputs:
- datatype: BYTES
  name: output
  shape: [ 3 ]
"""

validate_model_metadata(yaml.safe_load(data))<jupyter_output><empty_output><jupyter_text>Seldon Schema  arraypayload examples:- `{"data": {"names": ["a", "b"], "ndarray": [[1, 2], [3, 4]]}}`- `{"data": {"names": ["a", "b"], "tensor": {"values": [1, 2, 3, 4], "shape": [2, 2]}}`<jupyter_code>data = """
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon
inputs:
- messagetype: tensor
  schema:
    names: [a, b, c, d]
    shape: [ 4 ]
outputs:
- messagetype: tensor
  schema:
    shape: [ 1 ]
"""

validate_model_metadata(yaml.safe_load(data))<jupyter_output><empty_output><jupyter_text>json datapayload example: `{"jsonData": {"my-custom-field": "my-custom-data"}}`<jupyter_code>data = """
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon
inputs:
- messagetype: jsonData
outputs:
- messagetype: tensor
  schema:
    shape: [ 1 ]
"""

validate_model_metadata(yaml.safe_load(data))<jupyter_output><empty_output><jupyter_text>json data with user's schemapayload example: `{"jsonData": {"names": ["a", "b"], "data": [1, 2]}}`<jupyter_code>data = """
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon
inputs:
- messagetype: jsonData
  schema:
      type: object
      properties:
          names:
              type: array
              items:
                  type: string
          data:
            type: array
            items:
                type: number
                format: double
outputs:
- messagetype: tensor
  schema:
    shape: [ 1 ]
"""

validate_model_metadata(yaml.safe_load(data))<jupyter_output><empty_output><jupyter_text>str datapayload example: `{"strData": "some test input"}`<jupyter_code>data = """
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon
inputs:
- messagetype: strData
outputs:
- messagetype: tensor
  schema:
    shape: [ 1 ]
"""

validate_model_metadata(yaml.safe_load(data))<jupyter_output><empty_output><jupyter_text>custom<jupyter_code>data = """
name: my-model-name
versions: [ my-model-version-01 ]
platform: seldon
inputs:
- messagetype: customData
  schema:
    my-names: ["a", "b", "c"]
outputs:
- messagetype: tensor
  schema:
    shape: [ 1 ]
"""

validate_model_metadata(yaml.safe_load(data))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15312046444121916, 'fraction_numerical': 0.011973875181422351, 'mean_word_length': 4.374269005847953, 'pattern_counts': {'":': 14, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '209056', 'license': 'Apache-2.0', 'n_tokens_mistral': 1018, 'n_tokens_neox': 969, 'n_words': 201, 'path': 'examples/models/metadata/metadata_schema_examples.ipynb', 'repo_name': 'gvashishtha/seldon-core', 'size': '2756'}