Пример #1
0
def QuestionAnswer(resource, *args, **kwargs):
    """
    Loads a NLP question answering service or model.
    See the QuestionAnswerService class for the signature that implementations use.
    """
    factory_map = {
        'tensorrt': 'jetson_voice.models.nlp.QuestionAnswerEngine',
        'onnxruntime': 'jetson_voice.models.nlp.QuestionAnswerEngine'
    }

    return load_resource(resource, factory_map, *args, **kwargs)
Пример #2
0
def IntentSlot(resource, *args, **kwargs):
    """
    Loads a NLP joint intent/slot classifier service or model.
    See the IntentSlotService class for the signature that implementations use.
    """
    factory_map = {
        'tensorrt': 'jetson_voice.models.nlp.IntentSlotEngine',
        'onnxruntime': 'jetson_voice.models.nlp.IntentSlotEngine'
    }

    return load_resource(resource, factory_map, *args, **kwargs)
Пример #3
0
def TokenClassification(resource, *args, **kwargs):
    """
    Loads a NLP token classification (aka Named Entity Recognition) service or model.
    See the TokenClassificationService class for the signature that implementations use.
    """
    factory_map = {
        'tensorrt': 'jetson_voice.models.nlp.TokenClassificationEngine',
        'onnxruntime': 'jetson_voice.models.nlp.TokenClassificationEngine'
    }

    return load_resource(resource, factory_map, *args, **kwargs)
Пример #4
0
def TextClassification(resource, *args, **kwargs):
    """
    Loads a NLP text classification service or model.
    See the TextClassificationService class for the signature that implementations use.
    """
    factory_map = {
        'tensorrt': 'jetson_voice.models.nlp.TextClassificationEngine',
        'onnxruntime': 'jetson_voice.models.nlp.TextClassificationEngine'
    }

    return load_resource(resource, factory_map, *args, **kwargs)
Пример #5
0
def ASR(resource, *args, **kwargs):
    """
    Loads a streaming ASR service or model.
    See the ASRService class for the signature that implementations use.
    """
    factory_map = {
        'riva' : 'jetson_voice.backends.riva.RivaASRService',
        'tensorrt' : 'jetson_voice.models.asr.ASREngine',
        'onnxruntime' : 'jetson_voice.models.asr.ASREngine'
    }
    
    return load_resource(resource, factory_map, *args, **kwargs)
Пример #6
0
def AutoModel(resource, domain=None, *args, **kwargs):
    """
    Factory for automatically loading models and services.
    First the config is loaded and the type is checked.
    Then the correct instance for the resource is created.
    
    If a domain string is supplied (e.g. 'asr', 'nlp', 'tts'),
    then only resources from that domain will be created.
    """
    type_map = {
        # models
        'asr': (ASR, 'asr'),
        'asr_classification': (ASR, 'asr'),
        'intent_slot': (IntentSlot, 'nlp'),
        'qa': (QuestionAnswer, 'nlp'),
        'text_classification': (TextClassification, 'nlp'),
        'token_classification': (TokenClassification, 'nlp'),
        'tts': (TTS, 'tts'),

        # services
        'jarvis_asr': (ASR, 'asr')
    }

    config = load_resource(resource, None, *args, **kwargs)

    if 'type' not in config:
        raise ValueError(f"'type' setting missing from config '{config.path}'")

    if config.type not in type_map:
        raise ValueError(f"'{config.path}' has invalid 'type' ({config.type})")

    if domain:
        if type_map[config.type][1] != domain.lower():
            raise ValueError(
                f"invalid model selected - '{config.path}' has domain '{type_map[config.type][1]}', but AutoModel() was called with domain={domain}"
            )

    return type_map[config.type][0](config, *args, **kwargs)