Spaces:
Runtime error
Runtime error
File size: 997 Bytes
a50f42c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
from typing import Optional, List
from pydantic import BaseModel, Extra
class EntityType(BaseModel):
idx: int
label: str
class EntityTypeSet(BaseModel):
entity_types: List[EntityType]
relation_types: List[EntityType]
id_of_non_entity: int
groups: List[List[int]]
def __len__(self):
return len(self.entity_types) + len(self.relation_types)
def all_types(self):
return [*self.entity_types, *self.relation_types]
class Token(BaseModel):
text: str
start: int
end: int
class Entity(BaseModel):
id: int
text: str
start: int
end: int
ent_type: EntityType
confidence: Optional[float]
class Relation(BaseModel):
id: int
head: int
tail: int
rel_type: EntityType
class Sample(BaseModel):
idx: int
text: str
entities: List[Entity] = []
relations: List[Relation] = []
tokens: List[Token] = []
tags: List[int] = []
class SampleList(BaseModel):
samples: List[Sample]
|