forked from CyberZHG/keras-bert
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add datasets * Update demos * Update README
- Loading branch information
Showing
11 changed files
with
114 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
from .tokenizer import Tokenizer | ||
from .optimizers import * | ||
from .util import * | ||
from .datasets import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .pretrained import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# coding=utf-8 | ||
from __future__ import unicode_literals | ||
|
||
import os | ||
import shutil | ||
from collections import namedtuple | ||
from keras_bert.backend import keras | ||
|
||
__all__ = ['PretrainedInfo', 'PretrainedList', 'get_pretrained'] | ||
|
||
|
||
PretrainedInfo = namedtuple('PretrainedInfo', ['url', 'extract_name', 'target_name']) | ||
|
||
|
||
class PretrainedList(object): | ||
|
||
__test__ = PretrainedInfo( | ||
'https://github.com/CyberZHG/keras-bert/archive/master.zip', | ||
'keras-bert-master', | ||
'keras-bert', | ||
) | ||
|
||
multi_cased_base = 'https://storage.googleapis.com/bert_models/2018_11_23/multi_cased_L-12_H-768_A-12.zip' | ||
chinese_base = 'https://storage.googleapis.com/bert_models/2018_11_03/chinese_L-12_H-768_A-12.zip' | ||
wwm_uncased_large = 'https://storage.googleapis.com/bert_models/2019_05_30/wwm_uncased_L-24_H-1024_A-16.zip' | ||
wwm_cased_large = 'https://storage.googleapis.com/bert_models/2019_05_30/wwm_cased_L-24_H-1024_A-16.zip' | ||
chinese_wwm_base = PretrainedInfo( | ||
'https://storage.googleapis.com/hfl-rc/chinese-bert/chinese_wwm_L-12_H-768_A-12.zip', | ||
'publish', | ||
'chinese_wwm_L-12_H-768_A-12', | ||
) | ||
|
||
|
||
def get_pretrained(info): | ||
path = info | ||
if isinstance(info, PretrainedInfo): | ||
path = info.url | ||
path = keras.utils.get_file(fname=os.path.split(path)[-1], origin=path, extract=True) | ||
base_part, file_part = os.path.split(path) | ||
file_part = file_part.split('.')[0] | ||
if isinstance(info, PretrainedInfo): | ||
extract_path = os.path.join(base_part, info.extract_name) | ||
target_path = os.path.join(base_part, info.target_name) | ||
if not os.path.exists(target_path): | ||
shutil.move(extract_path, target_path) | ||
file_part = info.target_name | ||
return os.path.join(base_part, file_part) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import os | ||
from unittest import TestCase | ||
from keras_bert.datasets import get_pretrained, PretrainedList | ||
|
||
|
||
class TestGetPretrained(TestCase): | ||
|
||
def test_get_pretrained(self): | ||
path = get_pretrained(PretrainedList.__test__) | ||
self.assertTrue(os.path.exists(os.path.join(path, 'README.md'))) |