nealcly commited on
Commit
46a9ac6
·
1 Parent(s): c642908

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +11 -8
README.md CHANGED
@@ -14,24 +14,27 @@ from transformers import (
14
  set_seed,
15
  )
16
  import torch
17
-
18
  model_dir = "nealcly/detection-longformer"
19
  tokenizer = AutoTokenizer.from_pretrained(model_dir)
20
- model = AutoModelForSequenceClassification.from_pretrained(model_dir).to('cuda:0')
21
- threshold = 3.08583984375
22
  label2decisions = {
23
  0: "machine-generated",
24
  1: "human-written",
25
  }
26
-
27
- def detect(input_text):
28
  tokenize_input = tokenizer(input_text)
29
- tensor_input = torch.tensor([tokenize_input["input_ids"]]).to('cuda:0')
30
  outputs = model(tensor_input)
31
- is_machine = -outputs.logits[0][0].item() + threshold
32
- if is_machine > 0:
33
  decision = 0
34
  else:
35
  decision = 1
36
  print(f"The text is {label2decisions[decision]}.")
 
 
 
 
37
  ```
 
14
  set_seed,
15
  )
16
  import torch
17
+ device = 'cuda:0'
18
  model_dir = "nealcly/detection-longformer"
19
  tokenizer = AutoTokenizer.from_pretrained(model_dir)
20
+ model = AutoModelForSequenceClassification.from_pretrained(model_dir).to(device)
21
+
22
  label2decisions = {
23
  0: "machine-generated",
24
  1: "human-written",
25
  }
26
+ def detect(input_text,th=-3.08583984375):
 
27
  tokenize_input = tokenizer(input_text)
28
+ tensor_input = torch.tensor([tokenize_input["input_ids"]]).to(device)
29
  outputs = model(tensor_input)
30
+ is_machine = -outputs.logits[0][0].item()
31
+ if is_machine < th:
32
  decision = 0
33
  else:
34
  decision = 1
35
  print(f"The text is {label2decisions[decision]}.")
36
+
37
+ input_text = "Researchers at Stanford University and the SLAC National Accelerator Laboratory have discovered a way to transform a substance found in fossil fuels into diamonds with pressure and low heat. Diamond synthesis usually requires a large amount of energy, time, or the addition of a catalyst, which adds impurities. Diamondoids are tiny, odorless, and slightly sticky powders that resemble rock salt. They are made up of atoms arranged in the same pattern as diamonds, but they contain hydrogen. Diamondoids can reorganize into diamonds with surprisingly little energy, without passing through other forms of carbon, such as graphite. The method is currently only able to make specks of diamonds, and it is impractical until larger crystals can be formed." # human-written
38
+ input_text = "Reddit Talk is a new social audio product that allows subreddit moderators to start Clubhouse-like Talks. While moderators will have control over who can speak in the sessions, anybody on Reddit or Discord can join and listen in. It's like an open mic with your own personal mods in charge of taking care of everything else (like banning trolls). The idea is to create more friendly and interactive conversations among users rather than just endless battles between assholes. There are even 'subreddits for each type of topic moderated by their in context moderation team members."" The current moderation was created very quickly as popularity spiked within days after Reddit acquired it back in February 2019. We think this could be a great way to keep discussions active without having someone run them off into the abyss." # machine-generated
39
+ detect(input_text)
40
  ```