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

convert_dictionary.lua 897 B

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
  1. -- Copyright (c) 2017-present, Facebook, Inc.
  2. -- All rights reserved.
  3. --
  4. -- This source code is licensed under the license found in the LICENSE file in
  5. -- the root directory of this source tree. An additional grant of patent rights
  6. -- can be found in the PATENTS file in the same directory.
  7. --
  8. -- Usage: convert_dictionary.lua <dict.th7>
  9. require 'fairseq'
  10. require 'torch'
  11. require 'paths'
  12. if #arg < 1 then
  13. print('usage: convert_dictionary.lua <dict.th7>')
  14. os.exit(1)
  15. end
  16. if not paths.filep(arg[1]) then
  17. print('error: file does not exit: ' .. arg[1])
  18. os.exit(1)
  19. end
  20. dict = torch.load(arg[1])
  21. dst = paths.basename(arg[1]):gsub('.th7', '.txt')
  22. assert(dst:match('.txt$'))
  23. f = io.open(dst, 'w')
  24. for idx, symbol in ipairs(dict.index_to_symbol) do
  25. if idx > dict.cutoff then
  26. break
  27. end
  28. f:write(symbol)
  29. f:write(' ')
  30. f:write(dict.index_to_freq[idx])
  31. f:write('\n')
  32. end
  33. f:close()
Tip!

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

Comments

Loading...