Skip to content

Commit c36dbaa

Browse files
committed
Accelerating on Apple Silicon M1 chips
1 parent e658a88 commit c36dbaa

File tree

6 files changed

+19
-14
lines changed

6 files changed

+19
-14
lines changed

docs/install.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ Installation on Windows is **perfectly** supported. The full version `hanlp[full
6363
```
6464
````
6565

66+
````{margin} **Apple Silicon**
67+
```{note}
68+
HanLP also perfectly supports accelerating on Apple Silicon M1 chips, see [tutorial](https://www.hankcs.com/nlp/hanlp-official-m1-support.html).
69+
```
70+
````
71+
6672
| Flavor | Description |
6773
| ------- | ------------------------------------------------------------ |
6874
| default | This installs the default version which delivers the most commonly used functionalities. However, some heavy dependencies like TensorFlow are not installed. |
69-
| full | For experts who seek to maximize the efficiency via TensorFlow and C++ extensions, `pip install hanlp[full]` installs every dependency HanLP will use in production. `hanlp[full]` requires `Python<=3.8` due to `tensorflow==2.3.0`, which can be easily installed through conda: `conda install python=3.8 -y` |
75+
| full | For experts who seek to maximize the efficiency via TensorFlow and C++ extensions, `pip install hanlp[full]` installs every dependency HanLP will use in production. |
7076

7177

7278
## Install Models
@@ -103,4 +109,3 @@ Some TensorFlow/fastText models will ask you to install the missing TensorFlow/f
103109
pip install hanlp[full]
104110
```
105111

106-

hanlp/components/classifiers/transformer_classifier_tf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def inputs_to_samples(self, inputs, gold=False):
5050
attention_mask = [1] * len(token_ids)
5151
diff = max_length - len(token_ids)
5252
if diff < 0:
53-
logger.warning(
54-
f'Input tokens {tokens} exceed the max sequence length of {max_length - 2}. '
55-
f'The exceeded part will be truncated and ignored. '
56-
f'You are recommended to split your long text into several sentences within '
57-
f'{max_length - 2} tokens beforehand.')
53+
# logger.warning(
54+
# f'Input tokens {tokens} exceed the max sequence length of {max_length - 2}. '
55+
# f'The exceeded part will be truncated and ignored. '
56+
# f'You are recommended to split your long text into several sentences within '
57+
# f'{max_length - 2} tokens beforehand.')
5858
token_ids = token_ids[:max_length]
5959
attention_mask = attention_mask[:max_length]
6060
segment_ids = segment_ids[:max_length]

hanlp/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# Author: hankcs
33
# Date: 2019-12-28 19:26
44

5-
__version__ = '2.1.0-alpha.62'
5+
__version__ = '2.1.0-alpha.63'
66
"""HanLP version"""

plugins/hanlp_demo/hanlp_demo/zh/tf/cws/train_ctb6_cws_albert.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Date: 2019-12-28 22:22
44

55
from hanlp.components.tok_tf import TransformerTokenizerTF
6-
from hanlp.datasets.cws.ctb import CTB6_CWS_TRAIN, CTB6_CWS_DEV, CTB6_CWS_TEST
6+
from hanlp.datasets.cws.ctb6 import CTB6_CWS_TRAIN, CTB6_CWS_DEV, CTB6_CWS_TEST
77
from tests import cdroot
88

99
cdroot()

plugins/hanlp_demo/hanlp_demo/zh/tf/cws/train_ctb6_cws_bert.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Date: 2019-12-28 22:22
44

55
from hanlp.components.tok_tf import TransformerTokenizerTF
6-
from hanlp.datasets.cws.ctb import CTB6_CWS_TRAIN, CTB6_CWS_DEV, CTB6_CWS_TEST
6+
from hanlp.datasets.cws.ctb6 import CTB6_CWS_TRAIN, CTB6_CWS_DEV, CTB6_CWS_TEST
77
from tests import cdroot
88

99
cdroot()
1010
tokenizer = TransformerTokenizerTF()
1111
save_dir = 'data/model/cws_bert_base_ctb6'
12-
# tagger.fit(CTB6_CWS_TRAIN, CTB6_CWS_DEV, save_dir, transformer='bert-base-chinese',
13-
# metrics='f1')
12+
tokenizer.fit(CTB6_CWS_TRAIN, CTB6_CWS_DEV, save_dir, transformer='chinese_L-12_H-768_A-12',
13+
metrics='f1')
1414
tokenizer.load(save_dir)
1515
print(tokenizer.predict(['中央民族乐团离开北京前往维也纳', '商品和服务']))
1616
tokenizer.evaluate(CTB6_CWS_TEST, save_dir=save_dir)

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@
4949
extras_require={
5050
'full': [
5151
'fasttext==0.9.1',
52-
'tensorflow==2.3.0',
53-
'bert-for-tf2==0.14.6',
52+
'tensorflow==2.6.0',
53+
'bert-for-tf2-mod==0.14.10',
5454
'py-params==0.9.7',
5555
'params-flow==0.8.2',
5656
'penman==0.6.2',

0 commit comments

Comments
 (0)