|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from abc import ABC |
|
|
from typing import Dict, Optional |
|
|
|
|
|
from nemo.core.classes import NeuralModule |
|
|
from nemo.core.neural_types import ChannelType, MaskType, NeuralType |
|
|
|
|
|
__all__ = ['EncoderModule'] |
|
|
|
|
|
|
|
|
class EncoderModule(NeuralModule, ABC): |
|
|
""" Base class for encoder neural module to be used in NLP models. """ |
|
|
|
|
|
@property |
|
|
def input_types(self) -> Optional[Dict[str, NeuralType]]: |
|
|
return { |
|
|
"input_ids": NeuralType(('B', 'T'), ChannelType()), |
|
|
"encoder_mask": NeuralType(('B', 'T'), MaskType()), |
|
|
} |
|
|
|
|
|
@property |
|
|
def output_types(self) -> Optional[Dict[str, NeuralType]]: |
|
|
return {"last_hidden_states": NeuralType(('B', 'T', 'D'), ChannelType())} |
|
|
|
|
|
@property |
|
|
def hidden_size(self) -> Optional[int]: |
|
|
raise NotImplementedError |
|
|
|