Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ColossalAI
Commits
62f71561
Unverified
Commit
62f71561
authored
Mar 29, 2023
by
ver217
Committed by
GitHub
Mar 29, 2023
Browse files
[coati] fix inference profanity check (#3299)
parent
5134ad5d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
6 deletions
+6
-6
applications/Chat/inference/requirements.txt
applications/Chat/inference/requirements.txt
+1
-0
applications/Chat/inference/utils.py
applications/Chat/inference/utils.py
+5
-6
No files found.
applications/Chat/inference/requirements.txt
View file @
62f71561
...
@@ -10,3 +10,4 @@ uvicorn
...
@@ -10,3 +10,4 @@ uvicorn
git+https://github.com/huggingface/transformers
git+https://github.com/huggingface/transformers
accelerate
accelerate
bitsandbytes
bitsandbytes
jieba
\ No newline at end of file
applications/Chat/inference/utils.py
View file @
62f71561
...
@@ -2,6 +2,7 @@ import re
...
@@ -2,6 +2,7 @@ import re
from
threading
import
Lock
from
threading
import
Lock
from
typing
import
Any
,
Callable
,
Generator
,
List
,
Optional
from
typing
import
Any
,
Callable
,
Generator
,
List
,
Optional
import
json
import
json
import
jieba
import
torch
import
torch
import
torch.distributed
as
dist
import
torch.distributed
as
dist
...
@@ -130,10 +131,7 @@ class ChatPromptProcessor:
...
@@ -130,10 +131,7 @@ class ChatPromptProcessor:
self
.
tokenizer
=
tokenizer
self
.
tokenizer
=
tokenizer
self
.
context
=
context
self
.
context
=
context
self
.
max_len
=
max_len
self
.
max_len
=
max_len
if
len
(
censored_words
)
>
0
:
self
.
censored_words
=
set
([
word
.
lower
()
for
word
in
censored_words
])
self
.
censored_pat
=
re
.
compile
(
f
'(
{
"|"
.
join
(
map
(
re
.
escape
,
censored_words
))
}
)'
,
flags
=
re
.
I
)
else
:
self
.
censored_pat
=
None
# These will be initialized after the first call of preprocess_prompt()
# These will be initialized after the first call of preprocess_prompt()
self
.
context_len
:
Optional
[
int
]
=
None
self
.
context_len
:
Optional
[
int
]
=
None
self
.
dialogue_placeholder_len
:
Optional
[
int
]
=
None
self
.
dialogue_placeholder_len
:
Optional
[
int
]
=
None
...
@@ -179,9 +177,10 @@ class ChatPromptProcessor:
...
@@ -179,9 +177,10 @@ class ChatPromptProcessor:
return
output
.
strip
()
return
output
.
strip
()
def
has_censored_words
(
self
,
text
:
str
)
->
bool
:
def
has_censored_words
(
self
,
text
:
str
)
->
bool
:
if
self
.
censored_
pat
is
None
:
if
len
(
self
.
censored_
words
)
==
0
:
return
False
return
False
return
self
.
censored_pat
.
search
(
text
)
is
not
None
intersection
=
set
(
jieba
.
cut
(
text
.
lower
()))
&
self
.
censored_words
return
len
(
intersection
)
>
0
class
LockedIterator
:
class
LockedIterator
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment