コード例 #1
0
news_titles = [
    "Half of all older adults are worried about dementia, survey says",
    "Telus invests $500,000 to bring wireless service to First Nation’s community in B.C.",
    "Asteroid Bigger Than the Eiffel Tower Approaching Earth at 20 Times the Speed of Sound",
    "Night shift: Bottas beats Vettel by 0.012s for pole as Hamilton starts in P5",
    "Exclusive: John Barnes discusses Liverpool FC’s January transfer plans",
    "Maharashtra: Balasaheb, Pawar relation beyond politics",
    "Which words has Collins Dictionary included in its Brexicon?",
    "Paralympics: Australian cycling champion Modra killed in road collision",
    "Multistate salmonella outbreak causes one death: CDC",
]



LABEL_STUDIO_CONFIG ='''<View>
                    <Text name="post" value="$text"></Text>
                    <Choices name="label" toName="title" choice="multiple">
                        <Choice value="Economy"></Choice>
                        <Choice value="Technology"></Choice>
                        <Choice value="Sports"></Choice>
                        <Choice value="Science"></Choice>
                        <Choice value="Entertainment"></Choice>
                        <Choice value="Other"></Choice>
                    </Choices>
                    </View>'''

with WebUI(frontend_dir='label_studio', context={"label_studio":{"config":LABEL_STUDIO_CONFIG}, 'title':title}) as tru: # start http server in background
    for item in news_titles:
        label = tru.ask({"data": {"text": item}})
        print("data: {}, label: {}".format(item, label)) #output result
コード例 #2
0
        'value': 'economy',
        'shortcut': "['s']"
    },
    {
        'label': 'technology (d)',
        'value': 'technology',
        'shortcut': "['d']"
    },
    {
        'label': 'sports (f)',
        'value': 'sports',
        'shortcut': "['f']"
    },
    {
        'label': 'other (k)',
        'value': 'other',
        'shortcut': "['k']"
    },
    {
        'label': 'skip (enter)',
        'value': 'skip',
        'shortcut': "['enter']"
    },
]

with WebUI(context={'title': title}) as tru:  # start http server in background
    for item in news_titles:
        label = tru.ask({"html": item},
                        meta={"buttons": random.sample(controls, k=3)})
        print("data: {}, label: {}".format(item, label.y))  #output result
コード例 #3
0
        'shortcut': "['s']"
    },
    {
        'label': 'technology (d)',
        'value': 'technology',
        'shortcut': "['d']"
    },
    {
        'label': 'sports (f)',
        'value': 'sports',
        'shortcut': "['f']"
    },
    {
        'label': 'other (k)',
        'value': 'other',
        'shortcut': "['k']"
    },
    {
        'label': 'skip (enter)',
        'value': 'skip',
        'shortcut': "['enter']"
    },
]

with WebUI(context={
        'buttons': controls,
        'title': title
}) as tru:  # start http server in background
    for item in news_titles:
        label = tru.ask({"html": item})
        print("data: {}, label: {}".format(item, label.y))  #output result
コード例 #4
0
ファイル: ner_text.py プロジェクト: JayceeLee/trunklucator
""",
    """On August 10, 2015, Google Inc. announced plans to create a new public holding company, Alphabet Inc. Google CEO Larry Page made this announcement in a blog post on Google's official blog.[11] Alphabet would be created to restructure Google by moving subsidiaries from Google to Alphabet, narrowing Google's scope. The company would consist of Google as well as other businesses including X Development, Calico, Nest, Verily, Malta, Fiber, Makani, CapitalG, and GV.[6][12][13] Sundar Pichai, Product Chief, became the new CEO of Google, replacing Larry Page, who transitioned to the role of running Alphabet, along with Google co-founder Sergey Brin.[14][15]
"""
]

CONFIG = '''
<View>
  <Labels name="ner" toName="text">
    <Label value="Person"></Label>
    <Label value="Organization"></Label>
    <Label value="Date"></Label>
    <Label value="Location"></Label>
  </Labels>
  <Text name="text" value="$text"></Text>
</View>
'''
INTERFACES = [
    "basic", "load", "controls", "submit", "completions", "side-column"
]

with WebUI(
        frontend_dir='label_studio',
        context={"label_studio": {
            "config": CONFIG,
            "interfaces": INTERFACES
        }}) as tru:  # start http server in background
    for data in texts:
        completions = tru.ask({"data": {"text": data}})
        print("{}".format(json.dumps(completions, ensure_ascii=False)),
              flush=True)  #output result
コード例 #5
0
def get_annotations(data, default_sampling_strategy="random"):
    """Prompts annotator for label from command line and adds annotations to data 
    
    Keyword arguments:
        data -- an list of unlabeled items where each item is 
                [ID, TEXT, LABEL, SAMPLING_STRATEGY, CONFIDENCE]
        default_sampling_strategy -- strategy to use for each item if not already specified
    """

    controls = [
                {'label':'disaster-related (a)', 'value':1, 'shortcut':"['a']"}, 
                {'label':'not related (x)', 'value':0, 'shortcut':"['x']"}, 
                {'label':'back (arrow left)', 'value':2, 'shortcut':"['arrowleft']"}, 
                {'label':'save and exit (e)', 'value':"s", 'shortcut':"['e']"}, 
            ]


    with WebUI(context={'buttons':controls, 'title':'News annotation'}) as tru: # start http server in background
        ind = 0
        tru.update({"html":"<br><h3>Instruction</h3><br><pre>"+detailed_instructions+"</pre>"})
        while ind <= len(data):
            if ind < 0:
                ind = 0 # in case you've gone back before the first
            if ind < len(data):
                textid = data[ind][0]
                text = '<h5>'+data[ind][1]+'</h5>'
                label = data[ind][2]
                strategy =  data[ind][3]

                if textid in already_labeled:
                    print("Skipping seen "+label)
                    ind+=1
                else:
                    label = tru.ask({"html": text})
                    label = str(label.y)
                    tru.update({"html":""})

                    if label == "2":                   
                        ind-=1  # go back
                    elif label == "s":
                        break  # save and exit
                    else:
                        if not label == "1":
                            label = "0" # treat everything other than 1 as 0
                            
                        data[ind][2] = label # add label to our data

                        if data[ind][3] is None or data[ind][3] == "":
                            data[ind][3] = default_sampling_strategy # add default if none given
                        ind+=1        

            else:
                #last one - give annotator a chance to go back
                tru.update({"html":"<br><pre>"+last_instruction+"</pre>"})
                label = tru.ask({"html": text})
                label = str(label.y)
                if label == "2":
                    ind-=1
                else:
                    ind+=1

    return data
コード例 #6
0
controls = [
    {
        'label': 'Cat (a)',
        'value': 'cat',
        'shortcut': "['a']"
    },
    {
        'label': 'Dog (x)',
        'value': 'dog',
        'shortcut': "['x']"
    },
    {
        'label': 'Skip (enter)',
        'value': '',
        'shortcut': "['enter']"
    },
]


def img_tag(filename):
    return "<img src=\"/data/{}\">".format(filename)


with WebUI(data_dir='./images', context={
        'buttons': controls,
        'title': title
}) as tru:  # start http server in background
    for item in images:
        label = tru.ask({"html": img_tag(item)})
        print("image: {}, label: {}".format(item, label.y))  #output result