Skip to content

Commit

Permalink
Merge pull request #183 from ufal/annotation-interface-fixes
Browse files Browse the repository at this point in the history
Annotation interface fixes
  • Loading branch information
kasnerz authored Jan 23, 2025
2 parents 3c11dc3 + 5c3c420 commit d3bde6c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 21 deletions.
4 changes: 2 additions & 2 deletions factgenie/campaign.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ def get_overview(self):
example_cnt=pd.NamedAgg(column="example_idx", aggfunc="count"),
status=pd.NamedAgg(column="status", aggfunc="first"),
annotator_id=pd.NamedAgg(column="annotator_id", aggfunc="first"),
start=pd.NamedAgg(column="start", aggfunc="first"),
end=pd.NamedAgg(column="end", aggfunc="first"),
start=pd.NamedAgg(column="start", aggfunc="min"),
end=pd.NamedAgg(column="end", aggfunc="max"),
).reset_index()

for col in ["status", "annotator_id", "start", "end"]:
Expand Down
8 changes: 4 additions & 4 deletions factgenie/crowdsourcing.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ def get_annotator_batch(app, campaign, service_ids, batch_idx=None):
# no available batches
return []
else:
# preview mode
# preview mode with the specific batch
batch_idx = int(batch_idx)
annotator_group = 0

Expand All @@ -352,10 +352,10 @@ def get_annotator_batch(app, campaign, service_ids, batch_idx=None):
# we do not block the example if we are in preview mode
if annotator_id != PREVIEW_STUDY_ID:
db.loc[mask, "status"] = ExampleStatus.ASSIGNED
db.loc[mask, "start"] = start
db.loc[mask, "annotator_id"] = annotator_id

db.loc[mask, "start"] = start
db.loc[mask, "annotator_id"] = annotator_id
campaign.update_db(db)
campaign.update_db(db)

annotator_batch = get_examples_for_batch(db, batch_idx, annotator_group)
logging.info(f"Releasing lock for {annotator_id}")
Expand Down
21 changes: 14 additions & 7 deletions factgenie/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,25 @@ def get_optional_fields(self):
def postprocess_output(self, output):
extra_args = self.config.get("extra_args", {})

if extra_args.get("remove_suffix", ""):
suffix = self.config["extra_args"]["remove_suffix"]

if output.endswith(suffix):
output = output[: -len(suffix)]

# cut model generation at the stopping sequence
if extra_args.get("stopping_sequence", False):
stopping_sequence = self.config["extra_args"]["stopping_sequence"]
stopping_sequence = extra_args["stopping_sequence"]

# re-normalize double backslashes ("\\n" -> "\n")
stopping_sequence = stopping_sequence.encode().decode("unicode_escape")

if stopping_sequence in output:
output = output[: output.index(stopping_sequence)]

output = output.strip()

# strip the suffix from the output
if extra_args.get("remove_suffix", ""):
suffix = extra_args["remove_suffix"]

if output.endswith(suffix):
output = output[: -len(suffix)]

output = output.strip()
return output

Expand Down
3 changes: 3 additions & 0 deletions factgenie/static/js/annotate.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function goToAnnotation(example_idx) {
const options = annotation_set[example_idx].options;
const textFields = annotation_set[example_idx].textFields;

annotation_set[example_idx]["lastAccessedTime"] = Math.floor(Date.now() / 1000);

clearExampleLevelFields();

if (flags !== undefined) {
Expand Down Expand Up @@ -267,6 +269,7 @@ function saveCurrentAnnotations(example_idx) {
annotation_set[example_idx]["flags"] = collectFlags();
annotation_set[example_idx]["options"] = collectOptions();
annotation_set[example_idx]["textFields"] = collectTextFields();
annotation_set[example_idx]["lastSavedTime"] = Math.floor(Date.now() / 1000);
}

function submitAnnotations(campaign_id) {
Expand Down
14 changes: 7 additions & 7 deletions factgenie/static/js/span-annotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,17 +125,17 @@ class SpanAnnotator {

$element.on('mousedown', (e) => {
this.isSelecting = true;
this.startSpan = this._findClosestSpan(objectId, e.pageX, e.pageY);
this.startSpan = this._findClosestSpan(objectId, e.clientX, e.clientY);
});

$element.on('mousemove', (e) => {
if (this.isSelecting) {
const closestSpan = this.throttledFindClosestSpan(objectId, e.pageX, e.pageY);
const closestSpan = this.throttledFindClosestSpan(objectId, e.clientX, e.clientY);
if (closestSpan) {
this._updateHighlight(objectId, this.startSpan, closestSpan);
}
} else if (this.currentType === -1) {
const closestSpan = this._findClosestSpan(objectId, e.pageX, e.pageY);
const closestSpan = this._findClosestSpan(objectId, e.clientX, e.clientY);
if (closestSpan) {
this._previewEraserEffect(objectId, closestSpan);
}
Expand All @@ -146,7 +146,7 @@ class SpanAnnotator {
$element.on('mouseup', (e) => {
if (!this.isSelecting) return;
this.isSelecting = false;
const endSpan = this._findClosestSpan(objectId, e.pageX, e.pageY);
const endSpan = this._findClosestSpan(objectId, e.clientX, e.clientY);

if (this.startSpan && endSpan) {
if (this.currentType === -1) {
Expand Down Expand Up @@ -240,9 +240,9 @@ class SpanAnnotator {

$('.annotatable', doc.element).each((_, span) => {
const $span = $(span);
const offset = $span.offset();
const left = offset.left;
const top = offset.top;
const rect = span.getBoundingClientRect();
const left = rect.left;
const top = rect.top;
const right = left + $span.width();
const bottom = top + $span.height();

Expand Down
5 changes: 4 additions & 1 deletion factgenie/workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,10 @@ def save_record(mode, campaign, row, result):
last_run = campaign.metadata.get("last_run", int(time.time()))
filename = f"{dataset_id}-{split}-{setup_id}-{last_run}.jsonl"
elif mode == CampaignMode.CROWDSOURCING:
filename = f"{dataset_id}-{split}-{setup_id}-{annotator_id}.jsonl"
batch_idx = row["batch_idx"]
annotator_group = row.get("annotator_group", 0)
batch_end = int(row["end"])
filename = f"{batch_idx}-{annotator_group}-{annotator_id}-{batch_end}.jsonl"
elif mode == CampaignMode.LLM_GEN:
last_run = campaign.metadata.get("last_run", int(time.time()))
filename = f"{dataset_id}-{split}-{last_run}.jsonl"
Expand Down

0 comments on commit d3bde6c

Please sign in to comment.