Skip to content

Commit

Permalink
Remove the UNKNOWN from the preamble of lf.complete() to encourage th…
Browse files Browse the repository at this point in the history
…e LLMs to do reasoning instead of strict mapping.

PiperOrigin-RevId: 573323714
  • Loading branch information
yifenglou authored and langfun authors committed Oct 13, 2023
1 parent aa8f73e commit 5266187
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 36 deletions.
4 changes: 0 additions & 4 deletions langfun/core/structured/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import langfun.core as lf
from langfun.core.structured import mapping
from langfun.core.structured import schema as schema_lib
import pyglove as pg


Expand All @@ -30,7 +29,6 @@ class CompleteStructure(mapping.StructureToStructure):
INSTRUCTIONS:
1. Each MISSING field contains a Python annotation, please fill the value based on the annotation.
2. Classes for the MISSING fields are defined under CLASS_DEFINITIONS.
3. If a MISSING field could not be filled, mark it as `UNKNOWN`.
""")

# NOTE(daiyip): Set the input path of the transform to root, so this transform
Expand All @@ -56,7 +54,6 @@ class _Country(pg.Object):
'Africa', 'Asia', 'Europe', 'Oceania', 'North America', 'South America'
]
population: int
hobby: str


DEFAULT_COMPLETE_EXAMPLES: list[mapping.MappingExample] = [
Expand All @@ -68,7 +65,6 @@ class _Country(pg.Object):
founding_date=_Date(year=1776, month=7, day=4),
continent='North America',
population=33_000_000,
hobby=schema_lib.UNKNOWN,
),
)
),
Expand Down
46 changes: 14 additions & 32 deletions langfun/core/structured/completion_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class Itinerary(pg.Object):
'Type of itinerary.'
]
activities: list[Activity]
hotel: pg.typing.Str['.*Hotel'] | None


class TripPlan(pg.Object):
Expand Down Expand Up @@ -67,7 +66,6 @@ def test_render_no_examples(self):
INSTRUCTIONS:
1. Each MISSING field contains a Python annotation, please fill the value based on the annotation.
2. Classes for the MISSING fields are defined under CLASS_DEFINITIONS.
3. If a MISSING field could not be filled, mark it as `UNKNOWN`.
INPUT_OBJECT:
```python
Expand All @@ -78,22 +76,19 @@ def test_render_no_examples(self):
day=1,
# Type of itinerary.
type=MISSING(Literal['daytime', 'nighttime']),
activities=MISSING(list[Activity]),
hotel=None
activities=MISSING(list[Activity])
),
Itinerary(
day=2,
# Type of itinerary.
type=MISSING(Literal['daytime', 'nighttime']),
activities=MISSING(list[Activity]),
hotel=None
activities=MISSING(list[Activity])
),
Itinerary(
day=3,
# Type of itinerary.
type=MISSING(Literal['daytime', 'nighttime']),
activities=MISSING(list[Activity]),
hotel=None
activities=MISSING(list[Activity])
)
]
)
Expand Down Expand Up @@ -131,7 +126,6 @@ def test_render_no_class_definitions(self):
INSTRUCTIONS:
1. Each MISSING field contains a Python annotation, please fill the value based on the annotation.
2. Classes for the MISSING fields are defined under CLASS_DEFINITIONS.
3. If a MISSING field could not be filled, mark it as `UNKNOWN`.
INPUT_OBJECT:
```python
Expand All @@ -146,8 +140,7 @@ def test_render_no_class_definitions(self):
Activity(
description=MISSING(str)
)
],
hotel=None
]
),
Itinerary(
day=2,
Expand All @@ -157,8 +150,7 @@ def test_render_no_class_definitions(self):
Activity(
description=MISSING(str)
)
],
hotel=None
]
),
Itinerary(
day=3,
Expand All @@ -168,8 +160,7 @@ def test_render_no_class_definitions(self):
Activity(
description=MISSING(str)
)
],
hotel=None
]
)
]
)
Expand Down Expand Up @@ -203,16 +194,14 @@ def test_render_with_examples(self):
INSTRUCTIONS:
1. Each MISSING field contains a Python annotation, please fill the value based on the annotation.
2. Classes for the MISSING fields are defined under CLASS_DEFINITIONS.
3. If a MISSING field could not be filled, mark it as `UNKNOWN`.
INPUT_OBJECT:
```python
_Country(
name='United States of America',
founding_date=MISSING(_Date),
continent=MISSING(Literal['Africa', 'Asia', 'Europe', 'Oceania', 'North America', 'South America']),
population=MISSING(int),
hobby=MISSING(str)
population=MISSING(int)
)
```
Expand All @@ -234,8 +223,7 @@ class _Date:
day=4
),
continent='North America',
population=33000000,
hobby=UNKNOWN
population=33000000
)
```
Expand All @@ -249,22 +237,19 @@ class _Date:
day=1,
# Type of itinerary.
type=MISSING(Literal['daytime', 'nighttime']),
activities=MISSING(list[Activity]),
hotel=None
activities=MISSING(list[Activity])
),
Itinerary(
day=2,
# Type of itinerary.
type=MISSING(Literal['daytime', 'nighttime']),
activities=MISSING(list[Activity]),
hotel=None
activities=MISSING(list[Activity])
),
Itinerary(
day=3,
# Type of itinerary.
type=MISSING(Literal['daytime', 'nighttime']),
activities=MISSING(list[Activity]),
hotel=None
activities=MISSING(list[Activity])
)
]
)
Expand Down Expand Up @@ -294,7 +279,7 @@ def test_transform(self):
Activity(description='Take a walk around Fisherman\\'s Wharf and have dinner at one of the many seafood restaurants.'),
Activity(description='Visit Pier 39 and see the sea lions.'),
],
hotel=None),
),
Itinerary(
day=2,
type='daytime',
Expand All @@ -303,7 +288,7 @@ def test_transform(self):
Activity(description='Take a walk across the Golden Gate Bridge.'),
Activity(description='Visit the Japanese Tea Garden in Golden Gate Park.'),
],
hotel=None),
),
Itinerary(
day=3,
type='daytime',
Expand All @@ -312,7 +297,7 @@ def test_transform(self):
Activity(description='Visit the San Francisco Museum of Modern Art.'),
Activity(description='Take a cable car ride.'),
],
hotel=None),
),
]
)
```
Expand Down Expand Up @@ -361,7 +346,6 @@ def test_transform(self):
description='Visit Pier 39 and see the sea lions.'
),
],
hotel=None,
),
Itinerary(
day=2,
Expand All @@ -385,7 +369,6 @@ def test_transform(self):
)
),
],
hotel=None,
),
Itinerary(
day=3,
Expand All @@ -405,7 +388,6 @@ def test_transform(self):
),
Activity(description='Take a cable car ride.'),
],
hotel=None,
),
],
),
Expand Down

0 comments on commit 5266187

Please sign in to comment.