Skip to content

Commit d6f460e

Browse files
authored
Update artist model activateion (#3106)
* update * rename
1 parent 6a0be69 commit d6f460e

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

paddlenlp/transformers/artist/modeling.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
# limitations under the License.
1515

1616
import paddle
17+
import paddle.nn.functional as F
1718
from ..dallebart.modeling import VQGanDetokenizer
1819
from ..gpt.modeling import GPTLMHeadModel, GPTLMHead, GPTModel
1920

@@ -23,14 +24,17 @@
2324
'ArtistForConditionalGeneration',
2425
]
2526

27+
# set gelu_new
28+
F.gelu_python = F.gelu
29+
2630
pretrained_init_configuration = {
2731
"pai-painter-base-zh": {
2832
"vocab_size": 37512,
2933
"hidden_size": 768,
3034
"num_hidden_layers": 12,
3135
"num_attention_heads": 12,
3236
"intermediate_size": 3072,
33-
"hidden_act": "gelu",
37+
"hidden_act": "gelu_python",
3438
"hidden_dropout_prob": 0.0,
3539
"attention_probs_dropout_prob": 0.0,
3640
"max_position_embeddings": 288,
@@ -47,7 +51,7 @@
4751
"num_hidden_layers": 12,
4852
"num_attention_heads": 12,
4953
"intermediate_size": 3072,
50-
"hidden_act": "gelu",
54+
"hidden_act": "gelu_python",
5155
"hidden_dropout_prob": 0.0,
5256
"attention_probs_dropout_prob": 0.0,
5357
"max_position_embeddings": 288,
@@ -64,7 +68,7 @@
6468
"num_hidden_layers": 12,
6569
"num_attention_heads": 12,
6670
"intermediate_size": 3072,
67-
"hidden_act": "gelu",
71+
"hidden_act": "gelu_python",
6872
"hidden_dropout_prob": 0.0,
6973
"attention_probs_dropout_prob": 0.0,
7074
"max_position_embeddings": 288,
@@ -81,7 +85,7 @@
8185
"num_hidden_layers": 12,
8286
"num_attention_heads": 12,
8387
"intermediate_size": 3072,
84-
"hidden_act": "gelu",
88+
"hidden_act": "gelu_python",
8589
"hidden_dropout_prob": 0.0,
8690
"attention_probs_dropout_prob": 0.0,
8791
"max_position_embeddings": 288,
@@ -98,7 +102,7 @@
98102
"num_hidden_layers": 24,
99103
"num_attention_heads": 16,
100104
"intermediate_size": 4096,
101-
"hidden_act": "gelu",
105+
"hidden_act": "gelu_python",
102106
"hidden_dropout_prob": 0.0,
103107
"attention_probs_dropout_prob": 0.0,
104108
"max_position_embeddings": 288,

paddlenlp/transformers/dallebart/tokenizer.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def best_match(i):
101101

102102
def replace_person_token(t):
103103
"Used for CC12M"
104-
t = re.sub("<person>([,\s]*(and)*[,\s]*<person>)+", " people ", t)
104+
t = re.sub(r"<person>([,\s]*(and)*[,\s]*<person>)+", " people ", t)
105105
while "<person>" in t:
106106
t = t.replace("<person>",
107107
f" {random.choices(*tuple(zip(*person_token)))[0]} ", 1)
@@ -114,27 +114,27 @@ def fix_html(t):
114114

115115

116116
def replace_punctuation_with_commas(t):
117-
return re.sub("[()[\].,|:;?!=+~\-\/{}]", ",", t)
117+
return re.sub(r"[()[\].,|:;?!=+~\-\/{}]", ",", t)
118118

119119

120120
def simplify_quotes(t):
121121
return re.sub("""['"`]""", ' " ', t)
122122

123123

124124
def merge_quotes(t):
125-
return re.sub('(\s*"+\s*)+', ' " ', t)
125+
return re.sub(r'(\s*"+\s*)+', ' " ', t)
126126

127127

128128
def remove_comma_numbers(t):
129129

130130
def _f(t):
131-
return re.sub("(\d),(\d{3})", r"\1\2", t)
131+
return re.sub(r"(\d),(\d{3})", r"\1\2", t)
132132

133133
return _f(_f(t))
134134

135135

136136
def pre_process_dot_numbers(t):
137-
return re.sub("(\w)\.(\w)", rf"\1{temp_token}dot{temp_token}\2", t)
137+
return re.sub(r"(\w)\.(\w)", rf"\1{temp_token}dot{temp_token}\2", t)
138138

139139

140140
def post_process_dot_numbers(t):
@@ -152,15 +152,15 @@ def post_process_quotes(t):
152152

153153

154154
def pre_process_dates(t):
155-
return re.sub("(\d)/(\d)", rf"\1{temp_token}slash{temp_token}\2", t)
155+
return re.sub(r"(\d)/(\d)", rf"\1{temp_token}slash{temp_token}\2", t)
156156

157157

158158
def post_process_dates(t):
159159
return re.sub(f"{temp_token}slash{temp_token}", "/", t)
160160

161161

162162
def merge_commas(t):
163-
return re.sub("(\s*,+\s*)+", ", ", t)
163+
return re.sub(r"(\s*,+\s*)+", ", ", t)
164164

165165

166166
def add_space_after_commas(t):
@@ -170,14 +170,14 @@ def add_space_after_commas(t):
170170
def handle_special_chars(t):
171171
"Handle special characters"
172172
# replace "-" with a space when between words without space
173-
t = re.sub("(\w)-(\w)", r"\1 \2", t)
173+
t = re.sub(r"(\w)-(\w)", r"\1 \2", t)
174174
# always add space around some characters
175-
return re.sub("([%&\/$*])", r" \1 ", t)
175+
return re.sub(r"([%&\/$*])", r" \1 ", t)
176176

177177

178178
def expand_hashtags(t, hashtag_processor):
179179
"Remove # and try to split words"
180-
return re.sub("#(\w+)", lambda m: hashtag_processor(m.group(1)), t)
180+
return re.sub(r"#(\w+)", lambda m: hashtag_processor(m.group(1)), t)
181181

182182

183183
_re_ignore_chars = r"[_#\\]"
@@ -190,7 +190,7 @@ def ignore_chars(t):
190190

191191
def remove_extra_spaces(t):
192192
"Remove extra spaces (including \t and \n)"
193-
return re.sub("\s+", " ", t)
193+
return re.sub(r"\s+", " ", t)
194194

195195

196196
def remove_repeating_chars(t):

0 commit comments

Comments
 (0)