structure

class hanlp.common.structure.ConfigTracker(locals_: Dict, exclude=('kwargs', 'self', '__class__', 'locals_'))[source]

This base class helps sub-classes to capture their arguments passed to __init__, and also their types so that they can be deserialized from a config in dict form.

Parameters
  • locals – Obtained by locals().

  • exclude – Arguments to be excluded.

Examples

>>> class MyClass(ConfigTracker):
>>>     def __init__(self, i_need_this='yes') -> None:
>>>         super().__init__(locals())
>>> obj = MyClass()
>>> print(obj.config)
{'i_need_this': 'yes', 'classpath': 'test_config_tracker.MyClass'}
class hanlp.common.structure.History[source]

A history of training context. It records how many steps have passed and provides methods to decide whether an update should be performed, and to caculate number of training steps given dataloader size and gradient_accumulation.

num_training_steps(num_batches, gradient_accumulation)[source]

Caculate number of training steps.

Parameters
  • num_batches – Size of dataloader.

  • gradient_accumulation – Number of batches per update.

Returns:

step(gradient_accumulation)[source]

Whether the training procedure should perform an update.

Parameters

gradient_accumulation – Number of batches per update.

Returns

True to update.

Return type

bool