Skip to content

Commit

Permalink
v1.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
Two Dev committed Dec 30, 2024
1 parent 3ca5945 commit 478eaba
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 44 deletions.
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ With multilingual capabilities and advanced configuration options, it ensures pr
### Learning Process and Acknowledgements
As a newbie, I created Gemma Template based on what I read and learned from the following sources:

- Google Cookbook: [Advanced Prompting Techniques](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Advanced_Prompting_Techniques.ipynb)
- Google Cookbook: [Finetune_with_LLaMA_Factory](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Finetune_with_LLaMA_Factory.ipynb)
- Google Cookbook: [Finetuning Gemma for Function Calling](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Finetuning_Gemma_for_Function_Calling.ipynb)
- Alpaca: [Alpaca Lora Documention](https://github.com/tloen/alpaca-lora)
- Google Gemma Cookbook: [Advanced Prompting Techniques](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Advanced_Prompting_Techniques.ipynb)
- Google Gemma Cookbook: [Finetune_with_LLaMA_Factory](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Finetune_with_LLaMA_Factory.ipynb)
- Google Gemma Cookbook: [Finetuning Gemma for Function Calling](https://github.com/google-gemini/gemma-cookbook/blob/main/Gemma/Finetuning_Gemma_for_Function_Calling.ipynb)
- Alpaca: [Alpaca Lora Documentation](https://github.com/tloen/alpaca-lora)
- Unsloth: [Finetune Llama 3.2, Mistral, Phi-3.5, Qwen 2.5 & Gemma 2-5x faster with 80% less memory!](https://github.com/unslothai/unsloth)


Expand Down Expand Up @@ -66,7 +66,7 @@ It enhances text readability, aligns with linguistic nuances, and preserves orig
- Supports advanced response structure format customization.
- Compatible with other models such as LLaMa.
- Enhances dynamic prompts using Round-Robin loops.
- Outputs multiple formats such as Alpaca, GPT, and STF text.
- Outputs multiple formats such as Text, Alpaca and GPT conversions.

**Installation**
----------------
Expand Down Expand Up @@ -125,7 +125,7 @@ print(response)
You are a multilingual professional writer.
Rewrite the text with a more engaging and creative tone. Use vivid imagery, descriptive language, and a conversational style to captivate the reader.
Rewrite the text to be more search engine friendly. Incorporate relevant keywords naturally, improve readability, and ensure it aligns with SEO best practices.
# Role:
You are a highly skilled professional content writer, linguistic analyst, and multilingual expert specializing in structured writing and advanced text processing.
Expand Down Expand Up @@ -156,7 +156,7 @@ Text Analysis 3: These are common English words, indicating the text is in Engli
Example 2: Bigrams (two words)
technology as => English
Text Analysis 2: Frequent bigrams in Vietnamese confirm the language context.
Text Analysis 2: Frequent bigrams in English confirm the language context.
Example 3: Trigrams (three words)
technology as Gemini => English
Expand All @@ -167,17 +167,17 @@ The linguistic analysis confirms the text is predominantly in English. Consequen
# Response Structure Format:
You must follow the response structure:
**Custom Title (Title):** Rewrite the title to make it concise, memorable, and optimized for SEO.
**Custom Description (Description):** Write description of the article in one or two sentences while focusing on reader benefits and engage curiosity.
**Custom Article (Article):** Rewrite this content to be SEO-friendly. Include relevant tags, optimize the title and subheadings, and ensure the text flows naturally for search engines and readers.
**Custom Main Points (Main Points):** Simplify the original key points to make them clearer and more reader-friendly.
**Custom Categories (Categories):** Assign appropriate categories to the article based text or target audience.
**Custom Tags (Tags):** Create tags to include relevant keywords. Ensure the tags align with popular search queries.
**Custom Title (Title):** Rewrite the title to reflect the main keyword and topic.
**Custom Description (Meta Description):** Rewrite the description with a bold claim or statistic to grab attention.
**Custom Article (Edit Article):** Reimagine this article with a more engaging and creative tone. Add metaphors, analogies, or storytelling elements to make it more captivating for readers.
**Custom Main Points (Highlights):** Summarize the main ideas into concise, actionable key points for added context to make them more engaging.
**Custom Categories (Topics):** Assign appropriate categories to the article based text or target audience.
**Custom Tags (Keywords):** Focus use tags that reflect the article’s subtopics or themes for better SEO.
By adhering to this format, the response will maintain linguistic integrity while enhancing professionalism, structure and alignment with user expectations.
# Text:
Gemma open models are built from _____ same research _____ technology as Gemini models. Gemma 2 comes in 2B, 9B _____ 27B and Gemma 1 comes in 2B and 7B sizes.
Gemma open models are built from the same research _____ technology as Gemini models. Gemma 2 comes in 2B, 9B and 27B _____ Gemma 1 comes in 2B _____ 7B sizes.
<end_of_turn>
<start_of_turn>model
Expand Down
2 changes: 1 addition & 1 deletion gemma_template/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
__url__ = "https://github.com/thewebscraping/gemma-template"
__author__ = "Tu Pham"
__author_email__ = "thetwofarm@gmail.com"
__version__ = "0.1.5"
__version__ = "0.1.6"
__license__ = "Apache-2.0"
24 changes: 12 additions & 12 deletions gemma_template/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@
"""

USER_TEMPLATE = """{system_template}
{prompt_template}
{instruction_template}
{structure_template}
# Text:
{document}
"""

GEMMA_PROMPT_TEMPLATE = """<start_of_turn>user
{user_template}<end_of_turn>
Expand Down Expand Up @@ -55,7 +66,7 @@
Example 2: Bigrams (two words)
{bigrams}
Text Analysis 2: Frequent bigrams in Vietnamese confirm the language context.
Text Analysis 2: Frequent bigrams in {language} confirm the language context.
Example 3: Trigrams (three words)
{trigrams}
Expand All @@ -72,17 +83,6 @@
By adhering to this format, the response will maintain linguistic integrity while enhancing professionalism, structure and alignment with user expectations.
""" # noqa: E501

USER_TEMPLATE = """{system_template}
{prompt_template}
{instruction_template}
{structure_template}
# Text:
{document}
"""

VIETNAMESE_INSTRUCTION_TEMPLATE = """# Vai trò:
Bạn là một biên tập viên nội dung chuyên nghiệp, nhà phân tích ngôn ngữ và chuyên gia đa ngôn ngữ, chuyên về viết có cấu trúc và xử lý văn bản nâng cao.
Expand Down
34 changes: 17 additions & 17 deletions gemma_template/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ class StructureField(BaseTemplate):
""" # noqa: 501

_default_tag_positions: ClassVar[dict[str, int]] = {
"title": 0,
"description": 0,
"document": 0,
"main_points": 0,
"categories": 0,
"tags": 0,
"title": -1,
"description": -1,
"document": -1,
"main_points": -1,
"categories": -1,
"tags": -1,
}
_default_tag: ClassVar[dict] = {
"title": ["Title"],
Expand Down Expand Up @@ -237,7 +237,7 @@ class Template(BaseTemplate):
Example 2: Bigrams (two words)
technology as => English
Text Analysis 2: Frequent bigrams in Vietnamese confirm the language context.
Text Analysis 2: Frequent bigrams in English confirm the language context.
Example 3: Trigrams (three words)
technology as Gemini => English
Expand All @@ -249,16 +249,16 @@ class Template(BaseTemplate):
# Response Structure Format:
You must follow the response structure:
**Custom Title (Title):** Rewrite the title to reflect the main keyword and topic.
**Custom Description (Description):** Rewrite the description with a bold claim or statistic to grab attention.
**Custom Article (Article):** Rewrite this content to be SEO-friendly. Include relevant tags, optimize the title and subheadings, and ensure the text flows naturally for search engines and readers.
**Custom Main Points (Main Points):** Simplify the original key points to make them clearer and more reader-friendly.
**Custom Categories (Categories):** Assign appropriate categories to the article based text or target audience.
**Custom Tags (Tags):** Focus use tags that reflect the article’s subtopics or themes for better SEO.
**Custom Description (Meta Description):** Rewrite the description with a bold claim or statistic to grab attention.
**Custom Article (Edit Article):** Reimagine this article with a more engaging and creative tone. Add metaphors, analogies, or storytelling elements to make it more captivating for readers.
**Custom Main Points (Highlights):** Summarize the main ideas into concise, actionable key points for added context to make them more engaging.
**Custom Categories (Topics):** Assign appropriate categories to the article based text or target audience.
**Custom Tags (Keywords):** Focus use tags that reflect the article’s subtopics or themes for better SEO.
By adhering to this format, the response will maintain linguistic integrity while enhancing professionalism, structure and alignment with user expectations.
# Text:
Gemma open models are _____ from the same research and technology as Gemini models. Gemma 2 comes in 2B, 9B _____ 27B and Gemma 1 comes in 2B _____ 7B sizes.
Gemma open models are built from the same research _____ technology as Gemini models. Gemma 2 comes in 2B, 9B and 27B _____ Gemma 1 comes in 2B _____ 7B sizes.
<end_of_turn>
<start_of_turn>model
Expand Down Expand Up @@ -691,7 +691,7 @@ def get_user_kwargs(
if structure_template_str:
if isinstance(structure_template, Callable):
kwargs.setdefault(
"structure_attrs", self._get_structure_attrs(**kwargs)
"structure_attrs", self._get_structure_attrs(self._structure_items, **kwargs)
)
structure_template_str = structure_template(self, **kwargs)
else:
Expand Down Expand Up @@ -1077,7 +1077,7 @@ def _formatting_structure_user_fn(
**kwargs,
) -> str:
prompts = []
for field, data in self._get_structure_attrs(**kwargs).items():
for field, data in self._get_structure_attrs(self._structure_items, **kwargs).items():
if excluded_fields and field in excluded_fields:
continue

Expand Down Expand Up @@ -1125,13 +1125,13 @@ def _formatting_structure_model_fn(
prompts.append(template)
return "\n\n".join(prompts).strip()

def _get_structure_attrs(self, **kwargs):
def _get_structure_attrs(self, structure_data: dict, **kwargs):
mapping = {}
for field, (
bold_value,
custom_value,
default_value,
) in self._structure_items.items():
) in structure_data.items():
if field in kwargs:
mapping[field] = {
"prompt": self._get_value_by_position(field),
Expand Down

0 comments on commit 478eaba

Please sign in to comment.