示例#1
0
    def run_once(self, opts, mode, pred_save_file, verbose_output, verbose):
        logger = self.logger
        summ_s0 = self.summ_s0
        pragmatics = bbrsa.str2prag[opts.pragmatics](opts, logger)
        distractor = bbrsa.str2distr[opts.distractor](opts, logger)
        model = ONMTRSAModel(summ_s0, pragmatics, distractor, opts, logger)

        start_time = time.time()
        if verbose_output is None:
            acc, preds = self.evaluator.split_evaluate(model, self.src, mode,
                                                       opts)
        else:
            acc, preds, distractors = self.evaluator.split_evaluate(
                model, self.src, mode, opts, output_distractors=True)
        duration = time.time() - start_time

        res_dict = {'eval_duration': duration, 'listener_acc': acc}
        self._calculate_rouge(preds, res_dict)
        if verbose:
            self._display_results(opts, res_dict)
        if verbose_output:
            self._verbose_output(opts, res_dict, distractors, preds, verbose_output)
        if pred_save_file:
            self._record_results(opts, res_dict, preds, pred_save_file)
        del model
示例#2
0
def main():
    # managing package import for OpenNMT
    sys.path.insert(0, os.path.abspath(bbrsa.ONMT_DIR))  # ../myOpenNMT
    # https://askubuntu.com/questions/470982/how-to-add-a-python-module-to-syspath

    sent = "-lrb- cnn -rrb- the palestinian authority officially became the 123rd member of the international criminal court on wednesday , a step that gives the court jurisdiction over alleged crimes in palestinian territories . the formal accession was marked with a ceremony at the hague , in the netherlands , where the court is based . the palestinians signed the icc 's founding rome statute in january , when they also accepted its jurisdiction over alleged crimes committed `` in the occupied palestinian territory , including east jerusalem , since june 13 , 2014 . '' later that month , the icc opened a preliminary examination into the situation in palestinian territories , paving the way for possible war crimes investigations against israelis . as members of the court , palestinians may be subject to counter-charges as well . israel and the united states , neither of which is an icc member , opposed the palestinians ' efforts to join the body . but palestinian foreign minister riad al-malki , speaking at wednesday 's ceremony , said it was a move toward greater justice . `` as palestine formally becomes a state party to the rome statute today , the world is also a step closer to ending a long era of impunity and injustice , '' he said , according to an icc news release . `` indeed , today brings us closer to our shared goals of justice and peace . '' judge kuniko ozaki , a vice president of the icc , said acceding to the treaty was just the first step for the palestinians . `` as the rome statute today enters into force for the state of palestine , palestine acquires all the rights as well as responsibilities that come with being a state party to the statute . these are substantive commitments , which can not be taken lightly , '' she said . rights group human rights watch welcomed the development . `` governments seeking to penalize palestine for joining the icc should immediately end their pressure , and countries that support universal acceptance of the court 's treaty should speak out to welcome its membership , '' said balkees jarrah , international justice counsel for the group . `` what 's objectionable is the attempts to undermine international justice , not palestine 's decision to join a treaty to which over 100 countries around the world are members . '' in january , when the preliminary icc examination was opened , israeli prime minister benjamin netanyahu described it as an outrage , saying the court was overstepping its boundaries . the united states also said it `` strongly '' disagreed with the court 's decision . `` as we have said repeatedly , we do not believe that palestine is a state and therefore we do not believe that it is eligible to join the icc , '' the state department said in a statement . it urged the warring sides to resolve their differences through direct negotiations . `` we will continue to oppose actions against israel at the icc as counterproductive to the cause of peace , '' it said . but the icc begs to differ with the definition of a state for its purposes and refers to the territories as `` palestine . '' while a preliminary examination is not a formal investigation , it allows the court to review evidence and determine whether to investigate suspects on both sides . prosecutor fatou bensouda said her office would `` conduct its analysis in full independence and impartiality . '' the war between israel and hamas militants in gaza last summer left more than 2,000 people dead . the inquiry will include alleged war crimes committed since june . the international criminal court was set up in 2002 to prosecute genocide , crimes against humanity and war crimes . cnn 's vasco cotovio , kareem khadder and faith karimi contributed to this report ."
    sent2 = "marseille , france -lrb- cnn -rrb- the french prosecutor leading an investigation into the crash of germanwings flight 9525 insisted wednesday that he was not aware of any video footage from on board the plane . marseille prosecutor brice robin told cnn that `` so far no videos were used in the crash investigation . '' he added , `` a person who has such a video needs to immediately give it to the investigators . '' robin 's comments follow claims by two magazines , german daily bild and french paris match , of a cell phone video showing the harrowing final seconds from on board germanwings flight 9525 as it crashed into the french alps . all 150 on board were killed . paris match and bild reported that the video was recovered from a phone at the wreckage site . the two publications described the supposed video , but did not post it on their websites . the publications said that they watched the video , which was found by a source close to the investigation . `` one can hear cries of ` my god ' in several languages , '' paris match reported . `` metallic banging can also be heard more than three times , perhaps of the pilot trying to open the cockpit door with a heavy object . towards the end , after a heavy shake , stronger than the others , the screaming intensifies . then nothing . '' `` it is a very disturbing scene , '' said julian reichelt , editor-in-chief of bild online . an official with france 's accident investigation agency , the bea , said the agency is not aware of any such video . lt. col. jean-marc menichini , a french gendarmerie spokesman in charge of communications on rescue efforts around the germanwings crash site , told cnn that the reports were `` completely wrong '' and `` unwarranted . '' cell phones have been collected at the site , he said , but that they `` had n't been exploited yet . '' menichini said he believed the cell phones would need to be sent to the criminal research institute in rosny sous-bois , near paris , in order to be analyzed by specialized technicians working hand-in-hand with investigators . but none of the cell phones found so far have been sent to the institute , menichini said . asked whether staff involved in the search could have leaked a memory card to the media , menichini answered with a categorical `` no . '' reichelt told `` erin burnett : outfront '' that he had watched the video and stood by the report , saying bild and paris match are `` very confident '' that the clip is real . he noted that investigators only revealed they 'd recovered cell phones from the crash site after bild and paris match published their reports . `` that is something we did not know before . ... overall we can say many things of the investigation were n't revealed by the investigation at the beginning , '' he said . what was mental state of germanwings co-pilot ? german airline lufthansa confirmed tuesday that co-pilot andreas lubitz had battled depression years before he took the controls of germanwings flight 9525 , which he 's accused of deliberately crashing last week in the french alps . lubitz told his lufthansa flight training school in 2009 that he had a `` previous episode of severe depression , '' the airline said tuesday . email correspondence between lubitz and the school discovered in an internal investigation , lufthansa said , included medical documents he submitted in connection with resuming his flight training . the announcement indicates that lufthansa , the parent company of germanwings , knew of lubitz 's battle with depression , allowed him to continue training and ultimately put him in the cockpit . lufthansa , whose ceo carsten spohr previously said lubitz was 100 % fit to fly , described its statement tuesday as a `` swift and seamless clarification '' and said it was sharing the information and documents -- including training and medical records -- with public prosecutors . spohr traveled to the crash site wednesday , where recovery teams have been working for the past week to recover human remains and plane debris scattered across a steep mountainside . he saw the crisis center set up in seyne-les-alpes , laid a wreath in the village of le vernet , closer to the crash site , where grieving families have left flowers at a simple stone memorial . menichini told cnn late tuesday that no visible human remains were left at the site but recovery teams would keep searching . french president francois hollande , speaking tuesday , said that it should be possible to identify all the victims using dna analysis by the end of the week , sooner than authorities had previously suggested . in the meantime , the recovery of the victims ' personal belongings will start wednesday , menichini said . among those personal belongings could be more cell phones belonging to the 144 passengers and six crew on board . check out the latest from our correspondents . the details about lubitz 's correspondence with the flight school during his training were among several developments as investigators continued to delve into what caused the crash and lubitz 's possible motive for downing the jet . a lufthansa spokesperson told cnn on tuesday that lubitz had a valid medical certificate , had passed all his examinations and `` held all the licenses required . '' earlier , a spokesman for the prosecutor 's office in dusseldorf , christoph kumpa , said medical records reveal lubitz suffered from suicidal tendencies at some point before his aviation career and underwent psychotherapy before he got his pilot 's license . kumpa emphasized there 's no evidence suggesting lubitz was suicidal or acting aggressively before the crash . investigators are looking into whether lubitz feared his medical condition would cause him to lose his pilot 's license , a european government official briefed on the investigation told cnn on tuesday . while flying was `` a big part of his life , '' the source said , it 's only one theory being considered . another source , a law enforcement official briefed on the investigation , also told cnn that authorities believe the primary motive for lubitz to bring down the plane was that he feared he would not be allowed to fly because of his medical problems . lubitz 's girlfriend told investigators he had seen an eye doctor and a neuropsychologist , both of whom deemed him unfit to work recently and concluded he had psychological issues , the european government official said . but no matter what details emerge about his previous mental health struggles , there 's more to the story , said brian russell , a forensic psychologist . `` psychology can explain why somebody would turn rage inward on themselves about the fact that maybe they were n't going to keep doing their job and they 're upset about that and so they 're suicidal , '' he said . `` but there is no mental illness that explains why somebody then feels entitled to also take that rage and turn it outward on 149 other people who had nothing to do with the person 's problems . '' germanwings crash compensation : what we know . who was the captain of germanwings flight 9525 ? cnn 's margot haddad reported from marseille and pamela brown from dusseldorf , while laura smith-spark wrote from london . cnn 's frederik pleitgen , pamela boykoff , antonia mortensen , sandrine amiel and anna-maja rappard contributed to this report ."

    src = [sent, sent2]

    # setting up model
    s0 = ONMTSummarizer()
    pragmatics = BasicPragmatics(alpha=1)
    distractor = NextExampleDistractor(batch_size=s0.default_batch_size)
    model = ONMTRSAModel(s0, pragmatics, distractor)

    print('----- Starting summary with distractor')
    start_time = time.time()
    pred = model.incremental_s1(src, beam_size=10)
    print('----- Finished summary. Duration:', time.time() - start_time)
    print(pred)
    print('=================================')

    print('----- Starting summary without distractor')
    start_time = time.time()
    pred = model.summarize_s0(src, beam_size=10)
    print('----- Finished summary. Duration:', time.time() - start_time)
    print(pred)

    # print('=================================')
    # print('compare lengths:', len(log_probs1), len(log_probs2))
    # step = 0
    # for p1, p2 in zip(log_probs1, log_probs2):
    #     print('step', step, 'p1.shape', p1.shape, 'p2.shape', p2.shape)
    #     if p1.shape == p2.shape:
    #         diff = torch.gt(torch.abs(torch.add(p1, -p2)), 1e-5)
    #         resdiff = p1[diff].shape
    #         print('    differences:', resdiff)
    #         print('    p1[:6]', p1[:,:6])
    #         print('    p2[:6]', p2[:,:6])
    #     step += 1
    """
示例#3
0
def main():
    sys.path.insert(0, os.path.abspath(bbrsa.ONMT_DIR))
    with open(src_file, 'r') as f:
        src = f.readlines()

    s0 = ONMTSummarizer()
    pragmatics = BasicPragmatics(alpha=5)
    distractor = NextExampleDistractor(batch_size=s0.default_batch_size)
    model = ONMTRSAModel(s0, pragmatics, distractor)

    print('----- Starting summary with distractor')
    start_time = time.time()
    pred1 = model.incremental_s1(src, beam_size=10, truncate=400)
    print('----- Finished summary. Duration:', time.time() - start_time)

    print('----- Starting summary without distractor')
    start_time = time.time()
    pred2 = model.summarize_s0(src, n_best=30, beam_size=30, truncate=400)
    print('----- Finished summary. Duration:', time.time() - start_time)
    for i, l in enumerate(pred2):
        print('#### Sentence', i, '####')
        for j, x in enumerate(l):
            print('(' + str(j) + ')', x)
示例#4
0
def main():
    sys.path.insert(0, os.path.abspath(bbrsa.ONMT_DIR))
    with open(src_file, 'r') as f:
        src = f.readlines()
    with open(tgt_file, 'r') as f:
        tgt = f.readlines()

    s0 = ONMTSummarizer()
    pragmatics = BasicPragmatics(alpha=2)
    distractor = NextNDistractor(batch_size=s0.default_batch_size, N=1)
    model = ONMTRSAModel(s0, pragmatics, distractor)

    print('----- Starting summary with distractor')
    start_time = time.time()
    pred1 = model.incremental_s1(src, beam_size=10, truncate=400)
    print('----- Finished summary. Duration:', time.time() - start_time)

    print('----- Starting summary without distractor')
    start_time = time.time()
    pred2 = model.summarize_s0(src, beam_size=10, truncate=400)
    print('----- Finished summary. Duration:', time.time() - start_time)

    display(['s1', 's0'], [pred1, pred2])
示例#5
0
# evaluator = Evaluator(eval_s0, logger=logger)

opts.gpu = False
opts.batch_size = 1
opts.beam_size = 20
opts.n_best = 1
opts.prag_alpha = 1.5
opts.bert_distr_repl_search_top = 5
opts.bert_distr_repl_search_bottom = 10
opts.bert_distr_no_subword_repl = True
opts.bert_distr_exclusion_set = 3

summ_s0 = ONMTSummarizer(opts, args.model, logger=logger)
pragmatics = MemoizedListener(opts)  # ok
distractor = BertDistractor(opts)
model = ONMTRSAModel(summ_s0, pragmatics, distractor, opts)

# src = ['police arrested five climate-change protesters friday after they sought to disrupt loading of a french arctic research and supply vessel , a spokesman for the protesters said .']

# with open(src_path, 'r') as f:
#     src = [s.strip() for s in f.readlines()]
# with open(tgt_path, 'r') as f:
#     tgt = [s.strip() for s in f.readlines()]

src = [
    "china 's army has won a war against a toy maker without firing a shot ."
]
tgt = ["chinese army wins legal war with toy maker"]

print('Running incremental s1 on %s' % ('gpu' if opts.gpu else 'cpu'))
示例#6
0
args = parser.parse_args()

logger = init_logger(no_format=True, print_level=logging.DEBUG)
# eval_s0 = ONMTSummarizer(opts, part1_model_path)
# evaluator = Evaluator(eval_s0, logger=logger)

opts.gpu = True
opts.batch_size = 32
opts.beam_size = 10
opts.n_best = 1

opts.distractor = 'next_1'

print(opts)

model = ONMTRSAModel.from_opts(opts, part1_model_path)

# summ_s0 = ONMTSummarizer(opts, args.model, logger=logger)
# pragmatics = BasicPragmatics(opts) # ok
# distractor = NextExampleDistractor(opts)
# model = ONMTRSAModel(summ_s0, pragmatics, distractor, opts)

evaluator = Evaluator.from_opts(opts, part2_model_path, logger=logger)

with open(large_clean_input_path, 'r') as f:
    src = [s.strip() for s in f.readlines()]

"""
print('Running incremental s1')
start_time = time.time()
s1pred = model.incremental_s1(src, opts)
示例#7
0
import sys, os
import torch
import bbrsa

from bbrsa.distractors import BertDistractor, NextExampleDistractor, AsIsDistractor
from bbrsa.bbrsa import ONMTRSAModel
from bbrsa.summarizers import ONMTSummarizer
from bbrsa.pragmatics import BasicPragmatics, GrowingAlphaPragmatics

opts = bbrsa.DEFAULT_OPTS

s0 = ONMTSummarizer(opts, '/home/hansonlu/myOpenNMT/models/gigaword_copy_acc_51.78_ppl_11.71_e20.pt')
pragmatics = BasicPragmatics(opts)
distr = BertDistractor(opts)
model = ONMTRSAModel(s0, pragmatics, distr, opts)

src = ['police arrested five anti-nuclear protesters thursday after they sought to disrupt loading of a french nuclear research and supply vessel in antarctica , a spokesman for the protesters said .']
    # 'military arrested five anti-nuclear protesters thursday after they sought to disrupt loading of an american nuclear research and supply vessel , a spokesman for the protesters said .']
# print(distr.generate(src, repl_search_topk=10, ensure_different=True))

# print('\nNormal beam search:')
# print(model.incremental_s1(src, n_best=10, beam_size=10))

print('\nSummarizing with diverse beam search:')
# print(model.incremental_s1(src, n_best=10, diverse_beam='rank', beam_size=10))

# print(model.summarize_s0(src, n_best=10, diverse_beam='rank', beam_size=10))

# opts.set_values({'prag_alpha': 15., 'beam_size': 10, 'n_best': 3, 'diverse_beam': None})
#
# print(model.global_s1(src, opts))
示例#8
0
new_configs = {
    'batch_size': 5,
    'gpu': True,
    'prag_alpha': 1.5
}
opts.batch_size = 5
opts.gpu = True

logger = init_logger(no_format=True, print_level=logging.DEBUG)
eval_s0 = ONMTSummarizer(opts, part1_model_path)
evaluator = Evaluator(eval_s0, opts, logger=logger)

summ_s0 = ONMTSummarizer(opts, part2_model_path, logger=logger)
pragmatics = BasicPragmatics(opts)
distractor = NextExampleDistractor(opts)
model = ONMTRSAModel(summ_s0, pragmatics, distractor, opts)


# srcs = ['police arrested five climate-change protesters friday after they sought to disrupt loading of a french arctic research and supply vessel , a spokesman for the protesters said .']

with open(small_clean_input_path, 'r') as f:
    srcs = [s.strip() for s in f.readlines()]

start_time = time.time()
acc, hypotheses = evaluator.split_evaluate(model, distractor, srcs, opts, mode='incr_s1', verbose=True)
print('=== Finished. duration: {:.4}'.format(time.time() - start_time))
print('Accuracy: {:.5}'.format(acc))

# pred = model.summarize_s0(src, beam_size=10)

# tgt = 'police arrest climate-change protesters on saturday'
示例#9
0
from bbrsa.bbrsa import ONMTRSAModel
from bbrsa.summarizers import ONMTSummarizer
from bbrsa.distractors import NextExampleDistractor, IdenticalDistractor, NextNDistractor
from bbrsa.pragmatics import BasicPragmatics, GrowingAlphaPragmatics, MemoizedListener
from bbrsa.utils import init_logger, display, ProbAttnDump

logger = init_logger(no_format=True, print_level=logging.DEBUG)

giga_config_path = 'onmt_configs/giga.yml'
s0 = ONMTSummarizer(config_path=giga_config_path, logger=logger)
pragmatics = GrowingAlphaPragmatics(alpha=1, steps=3, logger=logger)
distractor = NextNDistractor(batch_size=s0.default_batch_size,
                             N=1,
                             logger=logger)
model = ONMTRSAModel(s0, pragmatics, distractor, logger=logger)

src = [
    'police arrested five anti-nuclear protesters friday after they sought to disrupt loading of a french antarctic research and supply vessel , a spokesman for the protesters said .',
    'police arrested five anti-nuclear protesters friday after they sought to disrupt loading of an american antarctic research and supply vessel , a spokesman for the protesters said .',
    'french police arrested five anti-nuclear protesters friday after they sought to disrupt loading of a french antarctic research and supply vessel , a spokesman for the protesters said .',
    'american police arrested five anti-nuclear protesters friday after they sought to disrupt loading of a french antarctic research and supply vessel , a spokesman for the protesters said .'
]

# src = ['a sample survey , launched by a taipei-based human resources bank , showed that ## percent of taiwanese office workers were willing to working on the chinese mainland , up #.# percent from #### .',
#     'a sample survey , launched by a taipei-based human resources bank , showed that ## percent of taiwanese office workers were willing to working on the chinese mainland , down #.# percent from #### .']
"""
'French police arrested five anti-nuclear protesters friday after they sought to disrupt loading of a french antarctic research and supply vessel , a spokesman for the protesters said .',
'French police arrested five anti-nuclear protesters friday after they sought to disrupt loading of an american antarctic research and supply vessel , a spokesman for the protesters said .'
"""
# dump = ProbAttnDump()
示例#10
0
args = parser.parse_args()

logger = init_logger(no_format=True, print_level=logging.DEBUG)
# eval_s0 = ONMTSummarizer(opts, part1_model_path)
# evaluator = Evaluator(eval_s0, logger=logger)

opts.gpu = False
opts.batch_size = 32
opts.beam_size = 10
opts.n_best = 1
opts.prag_alpha = 3.

summ_s0 = ONMTSummarizer(opts, args.model, logger=logger)
pragmatics = BasicPragmatics(opts)  # ok
distractor = BertDistractor(opts)
model = ONMTRSAModel(summ_s0, pragmatics, distractor, opts)

# src = ['police arrested five climate-change protesters friday after they sought to disrupt loading of a french arctic research and supply vessel , a spokesman for the protesters said .']

with open(medium_clean_input_path, 'r') as f:
    src = [s.strip() for s in f.readlines()]

print('Running incremental s1 on gpu')
pr = cProfile.Profile()
start_time = time.time()
pr.enable()
pred = model.incremental_s1(src, opts)
pr.disable()
print('=============================')
print('Finished running, took {:.4} s'.format(time.time() - start_time))