Showing posts with label Transformers. Show all posts
Showing posts with label Transformers. Show all posts

Thursday, January 22, 2026

Google Gemma 3 Vision: Python ile Görüntü İşleme, OCR ve Tarihi Analiz Deneyimleri

Google Gemma 3 Vision: Python ile Görüntü İşleme, OCR ve Tarihi Analiz Deneyimleri

Merhaba değerli arkadaşlar, ben Prof. Dr. Murat Karakaya. Murat Karakaya Akademi'ye hoş geldiniz. Bugün hem teknik hem de manevi açıdan çok özel bir inceleme ile karşınızdayım. 18 Mart Çanakkale Zaferi vesilesiyle, Google'ın yeni multimodal modeli Gemma 3 (4B)'ü, Çanakkale Savaşı'na ait tarihi fotoğraflar, belgeler ve menüler üzerinde test ettik.

Amacımız şu: Sadece 4 milyar parametreli küçük bir model, karmaşık tarihi belgeleri okuyabilir mi (OCR)? Yıpranmış siyah beyaz fotoğraflardaki duyguyu ve bağlamı anlayabilir mi? Ve en önemlisi, bunları Türkçe olarak hatasız yorumlayabilir mi? Sonuçlar beni gerçekten şaşırttı. Gelin, bu deneyimi ve Python kodlarını birlikte inceleyelim.

Bu duygusal ve teknik analizi baştan sona izlemek, modelin tarihi belgeleri nasıl yorumladığına şahit olmak için videoya göz atmanızı öneririm:

Bu Eğitimde Neler Öğreneceksiniz?

  • Hugging Face Transformers kütüphanesi ile Gemma 3 Vision kurulumu.
  • Gemma 3'ün OCR (Optik Karakter Tanıma) performansı ve kalori hesabı örneği.
  • Eski ve yıpranmış fotoğraflarda duygu ve bağlam analizi.
  • Yabancı dildeki (İngilizce/Yunanca) tarihi belgelerin analizi ve çevirisi.
  • Python ile Multimodal (Resim + Metin) pipeline oluşturma.

Gemma 3 Vision ve Teknik Altyapı

Gemma 3, sadece metin üreten bir LLM değil, aynı zamanda görüntüleri de "görebilen" bir VLM (Vision Language Model). Modelin içinde bir Vision Encoder bulunuyor. Bu encoder, görüntüyü küçük parçalara (patch) bölüyor, token'lara çeviriyor ve dil modelinin anlayabileceği bir formata dönüştürüyor.

Bu çalışmada, henüz çok yeni olduğu için Hugging Face'in transformers kütüphanesinin geliştirici sürümünü (GitHub branch) kullandık. Model olarak da 4 milyar parametreli (4B-it) versiyonu tercih ettik. Neden? Çünkü Colab'ın ücretsiz T4 GPU'sunda veya standart bir bilgisayarda (yaklaşık 7-8 GB VRAM ile) rahatlıkla çalışabiliyor.

Çanakkale Özel: Model Neleri Başardı?

1. OCR ve Mantıksal Çıkarım (Asker Menüsü)

Modele, Çanakkale Savaşı'nda askerlerimize verilen yemek listesini (15 Haziran, 26 Haziran gibi tarihlerin ve öğünlerin yazdığı eski bir belge) gösterdik. Gemma 3'ten sadece okumasını değil, askerlerin günlük kalorisini hesaplamasını ve günümüz hamburger menüsüyle kıyaslamasını istedik.

Sonuç: Model, tablodaki "Üzüm Hoşafı", "Yarım Ekmek" gibi silik yazıları kusursuz okudu. Askerin günlük ortalama 270 kalori aldığını hesapladı ve bunu günümüzün 1100 kalorilik menüsüyle kıyaslayarak aradaki uçurumu (yokluğu ve fedakarlığı) çok net ortaya koydu.

2. Duygu Analizi (Siperdeki Askerler)

Atatürk'ün cephede gözlemlediği anları anlattığı bir mektubun görselini ve siperdeki askerlerin bir fotoğrafını verdik. "Buradaki ruh halini özetle" dedik. Model, askerlerin yüzündeki kararlılık, korku, gerginlik ve vatan sevgisi ifadelerini metinle birleştirerek lise düzeyinde bir öğrencinin yazabileceği kalitede duygusal bir analiz yaptı.

3. Bağlamı Anlama (Fotoğraf Nerede Çekildi?)

Hiçbir yazı içermeyen, sadece askerlerin olduğu bir fotoğraf gösterdik. Model, üniformalardan, kask yapısından (her ne kadar kalpak yerine kask dese de) ve ortamdan bunun 1. Dünya Savaşı, Osmanlı Cephesi olduğunu ve muhtemelen Çanakkale veya Filistin cephesi olabileceğini "akıl yürüterek" buldu.

Python Kodları: Gemma 3 Vision Kurulumu

Bu analizi kendi bilgisayarınızda veya Google Colab'da yapmak için aşağıdaki Python kodlarını kullanabilirsiniz. Transformers kütüphanesinin güncel olduğundan emin olun.

import torch
from transformers import pipeline
from PIL import Image
import requests

# 1. Pipeline'ı Hazırlama
# 'image-text-to-text' görevi multimodal modeller içindir.
pipe = pipeline(
    "image-text-to-text",
    model="google/gemma-3-4b-it",
    device_map="auto",
    torch_dtype=torch.bfloat16 # Bellek tasarrufu için bfloat16 önemli
)

# 2. Resmi Yükleme (Örnek URL)
image_url = "https://example.com/canakkale_fotografi.jpg"
image = Image.open(requests.get(image_url, stream=True).raw)

# 3. Modele Mesaj Gönderme
# Gemma 3 için özel mesaj formatı
messages = [
    {
        "role": "user",
        "content": [
            {"type": "image", "image": image},
            {"type": "text", "text": "Bu resimde ne görüyorsun? Askerlerin ruh halini ve ortamı detaylıca analiz et."}
        ]
    }
]

# 4. Cevabı Üretme
output = pipe(messages, max_new_tokens=1024)
print(output[0]["generated_text"][-1]["content"])

Sıkça Sorulan Sorular (SSS)

1. Gemma 3 Türkçe OCR konusunda ne kadar başarılı?

4 milyar parametreli bir model için inanılmaz başarılı. Çanakkale menüsündeki eski yazı tiplerini, Atatürk'ün el yazısına yakın notlarını ve yıpranmış gazete küpürlerini %95'in üzerinde doğrulukla okuyup Türkçeye çevirebildi.

2. Bu model sadece CPU ile çalışır mı?

Evet, Llama.cpp gibi araçlarla CPU üzerinde çalıştırılabilir ancak bu rehberde kullandığımız Transformers kütüphanesi ile GPU (Colab T4 veya yerel RTX kartlar) kullanmak çok daha hızlı sonuç verir. CPU'da bir resmin analizi dakikalar sürebilir.

3. Llama 3.2 Vision ile farkı nedir?

Gemma 3, özellikle Türkçe dil desteği ve muhakeme (reasoning) yeteneği konusunda çok daha "yerel" hissettiriyor. Yaptığımız testlerde Türk tarihi ile ilgili bağlamları (üniformalar, coğrafya) şaşırtıcı derecede doğru tanıdı.

Sonuç

Bu 18 Mart'ta, teknolojiyi tarihimizi anlamak için kullandık. Gemma 3, 4 milyar parametresine rağmen, o dönemin zorluklarını, askerimizin fedakarlığını ve tarihin tozlu sayfalarındaki detayları bize bir kez daha, yapay zeka gözüyle gösterdi. Bize bu vatanı emanet eden tüm kahramanlarımızı saygı ve rahmetle anıyoruz.

Daha Fazlasını Keşfedin:
Yapay zeka modellerinin sınırlarını zorladığımız, teknik analizleri milli değerlerimizle harmanladığımız videoları kaçırmamak için Murat Karakaya Akademi YouTube kanalına abone olun.

Kanalı Ziyaret Et & Abone Ol 🚀

#MuratKarakayaAkademi #Gemma3 #VisionAI #CanakkaleZaferi #YapayZeka #Python

Tuesday, November 8, 2022

Text Generation in Deep Learning with Tensorflow & Keras: Fundamentals

Text Generation in Deep Learning with Tensorflow & Keras: Fundamentals

This tutorial is the first part of the “Text Generation in Deep Learning” series. We will cover all the topics related to Text Generation with sample implementations in Python Tensorflow KerasYou can access the codesvideos, and posts from the below links. In this part, we will learn the Fundamentals of Text Generation in Deep Learning.


You can access to all parts of the Deep Learning with Tensorflow & Keras Series at my blog muratlkarakaya.netYou can watch all these parts on the Murat Karakaya Akademi YouTube channel in ENGLISH or TURKISHYou can access the complete Python Keras codes in the video description of each part.

If you would like to learn more about Deep Learning with practical coding examples, please subscribe to my YouTube Channel or follow my blog on muratkarakaya.net. Please, turn on notifications to notify you when new parts are uploaded.





Controllable Text Generation in Deep Learning with Transformers (GPT3) using Tensorflow & Keras Tutorial Series

 

Controllable Text Generation in Deep Learning with Transformers (GPT3) using Tensorflow & Keras Tutorial Series

This is the index page of the “Controllable Text Generation in Deep Learning with Transformers (GPT3) using Tensorflow & Keras” tutorial series.

We will cover all the topics related to Controllable Text Generation with sample implementations in Python Tensorflow Keras.

You can access the codesvideos, and posts from the below links.

You may like to start with learning the Text Generation methods in Deep Learning with Tensorflow (TF) & Keras from this tutorial series.

If you would like to learn more about Deep Learning with practical coding examples, please subscribe to the Murat Karakaya Akademi YouTube Channel or follow my blog on muratkarakaya.net. Do not forget to turn on notifications so that you will be notified when new parts are uploaded.

Last updated: 14/05/2022



Photo by Ibrahim Boran on Unsplash

Saturday, November 5, 2022

Fundamentals of Controllable Text Generation

 

Fundamentals of Controllable Text Generation

Author: Murat Karakaya
Date created: 21 April 2021
Last modified: 24 May 2021
Description: This is an introductory tutorial on Controllable Text Generation in Deep Learning which is the second part of the “Controllable Text Generation with Transformers” series. This series will focus on developing TensorFlow (TF) / Keras implementation of Controllable Text Generation from scratch. You can access all these parts from my blog at muratkarakaya.net.

Before getting started, I assume that you have already reviewed:

Please ensure that you have completed the above tutorial series to easily follow the below discussions.

Accessible on:



Photo by Chris Leipelt on Unsplash

Friday, November 4, 2022

How to save and load a TensorFlow / Keras Model with Custom Objects?

 

How to save and load a TensorFlow / Keras Model with Custom Objects?

Author: Murat Karakaya
Date created: 30 May 2021
Last modified: 30 July 2021
Description: This tutorial will design and train a Keras model (miniature GPT3) with some custom objects (custom layers). We aim to learn how to save the trained model as a whole and load the saved model “TensorFlow SevedModel”.
Accessible on:



Photo by Markus Winkler on Unsplash

Bookmarks to the selected Deep Learning / Machine Learning Resources on the Web

 

Bookmarks to the selected Deep Learning / Machine Learning Resources on the Web

Author: Murat Karakaya
Date created: 19 May 2020
Last modified: 15 Dec 2021
Description: In this post, I share my bookmarks classified according to specific topics in Deep Learning / Machine Learning. Thus, you can save your time searching for similar information on the web. If you have any comments or updates please feel free to share with me!

If you are interested in Deep Learning / Machine learning, you can find hundreds of video tutorials with Python code samples in Jupyter notebooks at the following links:



Photo by Bernd Klutsch on Unsplash

Multi-Class Text Classification with a GPT3 Transformer block: An End-to-End Example

 

Multi-Class Text Classification with a GPT3 Transformer block: An End-to-End Example

Author: Murat Karakaya & Cansen Çağlayan
Date created: 05 Oct 2021
Last modified: 19 Oct 2021
Description: This tutorial has 2 parts as explained below. Part A: Data Analysis & Text Preprocessing and Part B: Text Classification. 



                                       Photo by Håkon Grimstad on Unsplash

Tuesday, November 1, 2022

Multi-Topic (Multi-Class) Text Classification With Various Deep Learning Models Tutorial Series

Multi-Topic (Multi-Class) Text Classification With Various Deep Learning Models Tutorial Series

Index Page

This is the index page of the “Multi-Topic (Multi-Class) Text Classification With Various Deep Learning Models” tutorial series.

Author: Murat Karakaya
Date created….. 17 Sept 2021
Date published… 11 March 2022
Last modified…. 09 April 2023

Description: This is a tutorial series that covers all the phases of text classification: Exploratory Data Analysis (EDA) of text, text preprocessing, and multi-class (multi-topic) text classification using the TF Data Pipeline and the Keras TextVectorization preprocessing layer.

We will design various Deep Learning models by using the Keras Embedding layer, Convolutional (Conv1D) layer, Recurrent (LSTM) layer, Transformer Encoder block, and pre-trained transformer (BERT).

We will use a Kaggle Dataset with 32 topics and more than 400K reviews.

We will cover all the topics related to solving Multi-Class Text Classification problems with sample implementations in Python TensorFlow Keras.

You can access the codesvideos, and posts from the below links.

If you would like to learn more about Deep Learning with practical coding examples, please subscribe to the Murat Karakaya Akademi YouTube Channel or follow my blog on muratkarakaya.net. Remember to turn on notifications so that you will be notified when new parts are uploaded.



Photo by Patrick Tomasso on Unsplash

PARTS

In this tutorial series, there will be several parts to cover the “Text Classification with various Deep Learning Models” in detail as follows. 

You can access all these parts on YouTube in ENGLISH or TURKISH!

You can access the complete codes as Colab Notebooks using the links given in each video description (Eng/TR) or you can visit the Murat Karakaya Akademi Github Repo.

Comments or Questions?

Please share your Comments or Questions.

Thank you in advance.

Do not forget to check out the following parts!

Take care!

You can access Murat Karakaya Akademi via:

YouTube

Facebook

Instagram

LinkedIn

GitHub

Kaggle

muratkarakaya.net