|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""The ALBERT configurations.""" |
|
|
|
from __future__ import absolute_import |
|
from __future__ import division |
|
from __future__ import print_function |
|
|
|
import six |
|
|
|
from official.nlp.bert import configs |
|
|
|
|
|
class AlbertConfig(configs.BertConfig): |
|
"""Configuration for `ALBERT`.""" |
|
|
|
def __init__(self, |
|
num_hidden_groups=1, |
|
inner_group_num=1, |
|
**kwargs): |
|
"""Constructs AlbertConfig. |
|
|
|
Args: |
|
num_hidden_groups: Number of group for the hidden layers, parameters in |
|
the same group are shared. Note that this value and also the following |
|
'inner_group_num' has to be 1 for now, because all released ALBERT |
|
models set them to 1. We may support arbitary valid values in future. |
|
inner_group_num: Number of inner repetition of attention and ffn. |
|
**kwargs: The remaining arguments are the same as above 'BertConfig'. |
|
""" |
|
super(AlbertConfig, self).__init__(**kwargs) |
|
|
|
|
|
|
|
|
|
if inner_group_num != 1 or num_hidden_groups != 1: |
|
raise ValueError("We only support 'inner_group_num' and " |
|
"'num_hidden_groups' as 1.") |
|
|
|
@classmethod |
|
def from_dict(cls, json_object): |
|
"""Constructs a `AlbertConfig` from a Python dictionary of parameters.""" |
|
config = AlbertConfig(vocab_size=None) |
|
for (key, value) in six.iteritems(json_object): |
|
config.__dict__[key] = value |
|
return config |
|
|