# Dropping a session from annotations

**URL:** <https://support.prodi.gy/t/dropping-a-session-from-annotations/6502>\
**Category:** Uncategorized\
**Created:** [April 22, 2023, 9:05pm UTC](https://support.prodi.gy/t/dropping-a-session-from-annotations/6502 "2023-04-22T21:05:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DerDiego13](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/derdiego13/32/3741_2.png) [@DerDiego13](https://support.prodi.gy/u/DerDiego13)\
**Post date:** [April 22, 2023, 9:05pm UTC](https://support.prodi.gy/t/dropping-a-session-from-annotations/6502/1 "2023-04-22T21:05:51Z")

</div>

I used spans.correct and the closed then window without hitting save as I didn't want to save the annotations. However, they somehow got saved and are now added to the dataset. With "prodigy stats -ls" I can see all my sessions. Is there a way to drop the last one from the data base and then just to continue and redo them?

---

<div class="post-metadata">

**Author:** ![ryanwesslen](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/ryanwesslen/32/2969_2.png) [@ryanwesslen](https://support.prodi.gy/u/ryanwesslen)\
**Post date:** [April 24, 2023, 5:48pm UTC](https://support.prodi.gy/t/dropping-a-session-from-annotations/6502/2 "2023-04-24T17:48:14Z")

</div>

hi @DerDiego13,

Thanks for your question and welcome to the Prodigy community 👋

You can run:

```python
from prodigy.components.db import connect
db = connect()
db.drop_dataset("mydata-ryan")

```

Of course, it's good to be cautious, so you may want to run `db-out` before running to save a backup for your data.

> [@Deleting certain annotation sessions](https://support.prodi.gy/t/deleting-certain-annotation-sessions/1144/2):
>
> Yes, this definitely looks like your event\_labels dataset has 12385 total examples. Maybe you accidentally added all of your annotations to the same dataset? To get to the bottom of this, you could run the db-out command, export it to a file and inspect it – maybe this will give you a better idea of what’s going on here? For example: prodigy db-out event\_labels \> event\_labels.jsonl This will give you a JSONL file with all the records. You can edit it manually, or use a script to filter it. Wh…

Here's an example. Let's assume I'm saving my annotations into a dataset called `mynerdata`.

Let's assume these annotations have been saved from two sessions: `diego` (20 records annotated) and `ryan` (10 records annotated).

```bash
python -m prodigy ner.correct mynerdata en_core_web_sm data/news_headlines.jsonl --label ORG
Using 1 label(s): ORG

✨ Starting the web server at http://localhost:8080 ...
Open the app in your browser and start annotating!

✔ Saved 30 annotations to database SQLite
Dataset: mynerdata
Session ID: 2023-04-24_13-37-59

```

You can now run in Python using the [database components](https://prodi.gy/docs/api-database#database):

```python
>>> from prodigy.components.db import connect
>>> db = connect()
>>> len(db.get_dataset("mynerdata"))
30

```

Let's now view `diego`'s and `ryan`'s annotations:

```python
>>> len(db.get_dataset_examples("mynerdata-diego"))
20
>>> len(db.get_dataset_examples("mynerdata-ryan"))
10

```

Now we'll use `db.drop_dataset` but for the `session` we want to drop (`mynerdata-ryan`):

```python
>>> db.drop_dataset("mynerdata-ryan")
True
>>> len(db.get_dataset_examples("mynerdata"))
20
>>> len(db.get_dataset_examples("mynerdata-diego"))
20
>>> len(db.get_dataset_examples("mynerdata-ryan"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: object of type 'NoneType' has no len()

```

So now `mynerdata` only has `diego`'s annotations, but we can't find the session for `ryan`.

You can also use this same logic to clean up old sessions based on some criteria (e.g., remove any sessions without any annotations):

> [@Dropping dataset from code doesn't properly delete examples](https://support.prodi.gy/t/dropping-dataset-from-code-doesnt-properly-delete-examples/437/5):
>
> @Superscope Internally, sessions are also datasets and the individual examples you’re annotating are linked to both a regular dataset and a session dataset (and potentially other datasets). If I remember correctly, Prodigy isn’t currently purging empty sessions automatically – but you should be able to delete them just like regular datasets, by using the session name (timestamp). Alternatively, you can also write a custom Python script that retrieves and checks the sessions and deletes them (e.…

Hope this helps!

---

<div class="post-metadata">

**Author:** ![DerDiego13](https://sea2.discourse-cdn.com/flex020/user_avatar/support.prodi.gy/derdiego13/32/3741_2.png) [@DerDiego13](https://support.prodi.gy/u/DerDiego13)\
**Post date:** [April 25, 2023, 8:49am UTC](https://support.prodi.gy/t/dropping-a-session-from-annotations/6502/3 "2023-04-25T08:49:32Z")

</div>

Hi, thank you very much for the reply. I will have a look into it.  
For now, I used "prodigy review" (as I needed to correct a few anyway) and will certainly come across the ones that were falsely added and then correct them along the way. Luckily, the dataset is not yet that long.
