From 42805294827741a618fc5e54af4e70854cf132ed Mon Sep 17 00:00:00 2001 From: hankcs Date: Sat, 7 Sep 2024 17:15:15 -0700 Subject: [PATCH] Fix extrapolation in relative transformer, fix: https://github.com/hankcs/HanLP/issues/1906 --- hanlp/layers/transformers/relative_transformer.py | 2 +- hanlp/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/hanlp/layers/transformers/relative_transformer.py b/hanlp/layers/transformers/relative_transformer.py index 9b60e12fd..d72d728bf 100644 --- a/hanlp/layers/transformers/relative_transformer.py +++ b/hanlp/layers/transformers/relative_transformer.py @@ -70,7 +70,7 @@ def forward(self, inputs: Tensor): """ bsz, seq_len = inputs.size() max_pos = self.padding_idx + seq_len - if max_pos > self.origin_shift: + if max_pos >= self.origin_shift: # recompute/expand embeddings if needed weights = self.get_embedding( max_pos * 2, diff --git a/hanlp/version.py b/hanlp/version.py index 96cf05ff3..97d0286d9 100644 --- a/hanlp/version.py +++ b/hanlp/version.py @@ -2,7 +2,7 @@ # Author: hankcs # Date: 2019-12-28 19:26 -__version__ = '2.1.0-beta.60' +__version__ = '2.1.0-beta.61' """HanLP version"""