This is a deepfake text detector (Longformer) trained using the testbeds in Github project 🏃 [Deepfake Text Detection in the Wild](https://github.com/yafuly/DeepfakeTextDetect). Here is a simple example of how to use the detector. However, we recommend utilizing the full detection pipeline available on our Github, which includes text preprocessing. ```python import torch import os from transformers import AutoModelForSequenceClassification,AutoTokenizer device = 'cuda:0' model_dir = "nealcly/detection-longformer" tokenizer = AutoTokenizer.from_pretrained(model_dir) model = AutoModelForSequenceClassification.from_pretrained(model_dir).to(device) label2decisions = { 0: "machine-generated", 1: "human-written", } def detect(input_text,th=-3.08583984375): tokenize_input = tokenizer(input_text) tensor_input = torch.tensor([tokenize_input["input_ids"]]).to(device) outputs = model(tensor_input) is_machine = -outputs.logits[0][0].item() if is_machine < th: decision = 0 else: decision = 1 print(f"The text is {label2decisions[decision]}.") 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 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 detect(input_text) ```