Views
No views yet
1import torch
2from torch import nn
3from transformers import AutoTokenizer, AutoModel, AutoModelForSequenceClassification, TrOCRProcessor, VisionEncoderDecoderModel
4from typing import List, Union
5from tqdm import tqdm
6import numpy as np
7import gc
8from craft_text_detector import Craft
9from PIL import Image
10import cv2
11import time
12import os
13import warnings
14
15warnings.filterwarnings('ignore')
16
17def ai_detector(essay):
18
19 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
20 CHECKPOINT_PATH = "ArtemBelogur/ai_detector_model"
21 MAX_LEN = 512
22
23 tokenizer = AutoTokenizer.from_pretrained(CHECKPOINT_PATH)
24 model = AutoModelForSequenceClassification.from_pretrained(
25 CHECKPOINT_PATH, max_position_embeddings=MAX_LEN
26 ).to(device)
27
28 y_pred = []
29 with torch.no_grad():
30 inputs = tokenizer(
31 essay,
32 padding=True,
33 truncation=True,
34 max_length=MAX_LEN,
35 return_tensors="pt",
36 ).to(device)
37 logits = model(**inputs).logits.cpu().numpy()
38 y_pred.extend(
39 (np.exp(logits) / np.sum(np.exp(logits), axis=-1, keepdims=True))[:, 1]
40 )
41
42 return y_pred[0]
43
44full_text = [
45 'Travel to the past is a common plot in modern literature or movies. Sometimes, people do it with an aim to change present where they encountered with unstandable obstacles or to sutisfy own inquisitivity. When the first one has too many side effects, the second desire is very natural for me. However, if I’m limited by time and opportunities, there is not any point to do it.\n\nThe first problem for me is that twenty four hours is too short period to do anything. I do not think that in that time I would be able to understand or percept the age where I am. Therefore I would prefer to reject the idea. But it is only the first reason.\n\nThe second thing that seems me strage is our confidence in being able to be alive and have a possibility to explore the world of the chosen time. The farther time ago we take, the harder for us to live there. I am pretty sure that If I chase the sixteen century and travelled to there, it would be very difficult to make any contact with the people that could not even understand me normally. So I am not talking about earlier periods of human history.\n\nTo summarize, the trip to the past sounds amazing and fascinating but only with the several conditions. Firstly, I want to be unlimited in time to be able to spend more than twenty four hours there. Second, I want to be unlimited in space to be able to visit different places, because you can not percept the age if you see only one small point of land. Third, there should be some mechanism to supply my basics human needs that I can not sutisfy in that time. It might seem that I want too much, but I really think that without all the conditions, the time travelling would be useless or only one directional.'
46]
47
48print('The probability that the essay is generated: ', ai_detector(essay))
49