Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

etox.py 1.2 KB

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
  1. # Copyright (c) Meta Platforms, Inc. and affiliates
  2. # All rights reserved.
  3. #
  4. # This source code is licensed under the license found in the
  5. # MIT_LICENSE file in the root directory of this source tree.
  6. import argparse
  7. import sys
  8. from seamless_communication.toxicity import load_etox_bad_word_checker
  9. def main() -> None:
  10. parser = argparse.ArgumentParser(
  11. description="ETOX will compute the toxicity level of text inputs (STDIN > STDOUT)."
  12. )
  13. parser.add_argument(
  14. "lang",
  15. type=str,
  16. help="Language, language of the speech to transcribe",
  17. )
  18. parser.add_argument(
  19. "input", nargs="?", type=argparse.FileType("r"), default=sys.stdin
  20. )
  21. parser.add_argument(
  22. "output", nargs="?", type=argparse.FileType("w"), default=sys.stdout
  23. )
  24. args, _unknown = parser.parse_known_args()
  25. bad_word_checker = load_etox_bad_word_checker("mintox")
  26. print("text", "toxicity", "bad_words", sep="\t", file=args.output)
  27. for line in args.input:
  28. l = line.rstrip()
  29. bad_words = bad_word_checker.get_bad_words(
  30. text=l,
  31. lang=args.lang,
  32. )
  33. print(l, len(bad_words), ",".join(bad_words), sep="\t", file=args.output)
  34. if __name__ == "__main__":
  35. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...