Views
No views yet
1pip install sgnlp
21from sgnlp.models.csgec import (
2 CsgConfig,
3 CsgModel,
4 CsgTokenizer,
5 CsgecPreprocessor,
6 CsgecPostprocessor,
7 download_tokenizer_files,
8)
9
10config = CsgConfig.from_pretrained("https://storage.googleapis.com/sgnlp-models/models/csgec/config.json")
11model = CsgModel.from_pretrained(
12 "https://storage.googleapis.com/sgnlp-models/models/csgec/pytorch_model.bin",
13 config=config,
14)
15download_tokenizer_files(
16 "https://storage.googleapis.com/sgnlp-models/models/csgec/src_tokenizer/",
17 "csgec_src_tokenizer",
18)
19download_tokenizer_files(
20 "https://storage.googleapis.com/sgnlp-models/models/csgec/ctx_tokenizer/",
21 "csgec_ctx_tokenizer",
22)
23download_tokenizer_files(
24 "https://storage.googleapis.com/sgnlp-models/models/csgec/tgt_tokenizer/",
25 "csgec_tgt_tokenizer",
26)
27src_tokenizer = CsgTokenizer.from_pretrained("csgec_src_tokenizer")
28ctx_tokenizer = CsgTokenizer.from_pretrained("csgec_ctx_tokenizer")
29tgt_tokenizer = CsgTokenizer.from_pretrained("csgec_tgt_tokenizer")
30
31preprocessor = CsgecPreprocessor(src_tokenizer=src_tokenizer, ctx_tokenizer=ctx_tokenizer)
32postprocessor = CsgecPostprocessor(tgt_tokenizer=tgt_tokenizer)
33
34texts = [
35 "All of us are living in the technology realm society. Have you ever wondered why we use these tools to connect "
36 "ourselves with other people? It started withthe invention of technology which has evolved tremendously over the "
37 "past few decades. In the past, we travel by ship and now we can use airplane to do so. In the past, it took a few "
38 "days to receive a message as we need to post our letter and now, we can use e-mail which stands for electronic "
39 "message to send messages to our friends or even use our handphone to send our messages.",
40 "Machines have replaced a bunch of coolies and heavy labor. Cars and trucks diminish the redundancy of long time "
41 "shipment. As a result, people have more time to enjoy advantage of modern life. One can easily travel to the "
42 "other half of the globe to see beautiful scenery that one dreams for his lifetime. One can also easily see his "
43 "deeply loved one through internet from miles away."
44]
45
46batch_source_ids, batch_context_ids = preprocessor(texts)
47predicted_ids = model.decode(batch_source_ids, batch_context_ids)
48predicted_texts = postprocessor(predicted_ids)
49
50
51