Views
No views yet
the atm protein is a single high molecular weight protein predominantly confined to the nucleus of human
fibroblasts but is present in both nuclear and microsomal fractions from human lymphoblast cells and peripheral
blood lymphocytes atm protein levels and localization remain constant throughout all stages of the cell cycle
truncated atm protein was not detected in lymphoblasts from ataxia telangiectasia patients homozygous
for mutations leading to premature protein termination exposure of normal human cells to gamma irradiation and the
radiomimetic drug neocarzinostatin had no effect on atm protein levels in contrast to a noted rise in p53 levels
over the same time interval these findings are consistent with a role for the atm protein in ensuring the fidelity
of dna repair and cell cycle regulation following genome damageThe ATM protein is a single, high-molecular-weight protein predominantly confined to the nucleus of human
fibroblasts, but is present in both nuclear and microsomal fractions from human lymphoblast cells and peripheral
blood lymphocytes. ATM protein levels and localization remain constant throughout all stages of the cell cycle.
Truncated ATM protein was not detected in lymphoblasts from ataxia-telangiectasia-patients homozygous
for mutations leading to premature protein termination. Exposure of normal human cells to gamma-irradiation and the
radiomimetic drug neocarzinostatin had no effect on ATM protein levels, in contrast to a noted rise in p53 levels
over the same time interval. These findings are consistent with a role for the ATM protein in ensuring the fidelity
of DNA repair and cell-cycle regulation following genome damage.1import torch
2import numpy as np
3from transformers import DistilBertTokenizerFast, DistilBertForTokenClassification
4
5checkpoint = "unikei/distilbert-base-re-punctuate"
6tokenizer = DistilBertTokenizerFast.from_pretrained(checkpoint)
7model = DistilBertForTokenClassification.from_pretrained(checkpoint)
8encoder_max_length = 256
9
10#
11# Split text to segments of length 200, with overlap 50
12#
13def split_to_segments(wrds, length, overlap):
14 resp = []
15 i = 0
16 while True:
17 wrds_split = wrds[(length * i):((length * (i + 1)) + overlap)]
18 if not wrds_split:
19 break
20
21 resp_obj = {
22 "text": wrds_split,
23 "start_idx": length * i,
24 "end_idx": (length * (i + 1)) + overlap,
25 }
26
27 resp.append(resp_obj)
28 i += 1
29 return resp
30
31
32#
33# Punctuate wordpieces
34#
35def punctuate_wordpiece(wordpiece, label):
36 if label.startswith('UPPER'):
37 wordpiece = wordpiece.upper()
38 elif label.startswith('Upper'):
39 wordpiece = wordpiece[0].upper() + wordpiece[1:]
40 if label[-1] != '_' and label[-1] != wordpiece[-1]:
41 wordpiece += label[-1]
42 return wordpiece
43
44
45#
46# Punctuate text segments (200 words)
47#
48def punctuate_segment(wordpieces, word_ids, labels, start_word):
49 result = ''
50 for idx in range(0, len(wordpieces)):
51 if word_ids[idx] == None:
52 continue
53 if word_ids[idx] < start_word:
54 continue
55 wordpiece = punctuate_wordpiece(wordpieces[idx][2:] if wordpieces[idx].startswith('##') else wordpieces[idx],
56 labels[idx])
57 if idx > 0 and len(result) > 0 and word_ids[idx] != word_ids[idx - 1] and result[-1] != '-':
58 result += ' '
59 result += wordpiece
60 return result
61
62
63#
64# Tokenize, predict, punctuate text segments (200 words)
65#
66def process_segment(words, tokenizer, model, start_word):
67
68 tokens = tokenizer(words['text'],
69 padding="max_length",
70 # truncation=True,
71 max_length=encoder_max_length,
72 is_split_into_words=True, return_tensors='pt')
73
74 with torch.no_grad():
75 logits = model(**tokens).logits
76 logits = logits.cpu()
77 predictions = np.argmax(logits, axis=-1)
78
79 wordpieces = tokens.tokens()
80 word_ids = tokens.word_ids()
81 id2label = model.config.id2label
82 labels = [[id2label[p.item()] for p in prediction] for prediction in predictions][0]
83
84 return punctuate_segment(wordpieces, word_ids, labels, start_word)
85
86
87#
88# Punctuate text of any length
89#
90def punctuate(text, tokenizer, model):
91 text = text.lower()
92 text = text.replace('\n', ' ')
93 words = text.split(' ')
94
95 overlap = 50
96 slices = split_to_segments(words, 150, 50)
97
98 result = ""
99 start_word = 0
100 for text in slices:
101 corrected = process_segment(text, tokenizer, model, start_word)
102 result += corrected + ' '
103 start_word = overlap
104 return result
105
106#
107# Example
108#
109text = "the atm protein is a single high molecular weight protein predominantly confined to the nucleus of human fibroblasts but is present in both nuclear and microsomal fractions from human lymphoblast cells and peripheral blood lymphocytes atm protein levels and localization remain constant throughout all stages of the cell cycle truncated atm protein was not detected in lymphoblasts from ataxia telangiectasia patients homozygous for mutations leading to premature protein termination exposure of normal human cells to gamma irradiation and the radiomimetic drug neocarzinostatin had no effect on atm protein levels in contrast to a noted rise in p53 levels over the same time interval these findings are consistent with a role for the atm protein in ensuring the fidelity of dna repair and cell cycle regulation following genome damage"
110result = punctuate(text, tokenizer, model)
111print(result)
112
113
114"""
115Output:
116The ATM protein is a single, high-molecular-weight protein predominantly confined to the nucleus of human fibroblasts, but is present in both nuclear and microsomal fractions from human lymphoblast cells and peripheral blood lymphocytes. ATM protein levels and localization remain constant throughout all stages of the cell cycle. Truncated ATM protein was not detected in lymphoblasts from ataxia-telangiectasia-patients homozygous for mutations leading to premature protein termination. Exposure of normal human cells to gamma-irradiation and the radiomimetic drug neocarzinostatin had no effect on ATM protein levels, in contrast to a noted rise in p53 levels over the same time interval. These findings are consistent with a role for the ATM protein in ensuring the fidelity of DNA repair and cell-cycle regulation following genome damage.
117"""