UFDModel¶
-
class
UFDModel
(adaptor_domain: sgnlp.models.ufd.modeling.UFDAdaptorDomainModel, adaptor_global: sgnlp.models.ufd.modeling.UFDAdaptorGlobalModel, feature_maper: sgnlp.models.ufd.modeling.UFDCombineFeaturesMapModel, classifier: sgnlp.models.ufd.modeling.UFDClassifierModel, loss_function: str = 'crossentrophyloss')[source]¶ The UFDModel used for running inferences. This model wraps the trained UFDAdaptorDomainModel, UFDAdaptorGlobalModel, UFDCombineFeaturesMapModel and the UFDClassifierModel.
The forward pass method executes a series of forward pass of these warpped models in the sequence defined in the paper and research code.
-
forward
(data_batch: torch.Tensor, labels: Optional[torch.Tensor] = None) → sgnlp.models.ufd.modeling.UFDModelOutput[source]¶ - Parameters
data_batch (torch.Tensor) – input tensor batch.
labels (Optional[torch.Tensor], optional) – list of labels. Defaults to None.
- Returns
output UFDModelOutput instance with loss and logits.
- Return type
- Example::
- from sgnlp.models.ufd import (
UFDModelBuilder, UFDPreprocessor
) model_builder = UFDModelBuilder() model_grp = model_builder.build_model_group() preprocessor = UFDPreprocessor() texts = [‘dieser film ist wirklich gut!’, ‘Diese Fortsetzung ist nicht so gut wie die Vorgeschichte’] text_feature = preprocessor(texts) ufd_model_output = model_grp[‘books_de_dvd’](**text_feature)
-